@m5kdev/backend 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/modules/ai/ai.repository.cjs +1 -1
- package/dist/src/modules/ai/ai.repository.d.mts +1 -1
- package/dist/src/modules/ai/ai.repository.mjs +1 -1
- package/dist/src/modules/ai/ai.service.cjs +1 -1
- package/dist/src/modules/ai/ai.service.mjs +1 -1
- package/dist/src/modules/auth/auth.dto.d.cts +2 -2
- package/dist/src/modules/auth/auth.dto.d.mts +2 -2
- package/dist/src/modules/auth/auth.lib.d.cts +5 -5
- package/dist/src/modules/auth/auth.lib.d.mts +6 -6
- package/dist/src/modules/auth/auth.middleware.d.mts +1 -1
- package/dist/src/modules/auth/auth.repository.cjs +1 -1
- package/dist/src/modules/auth/auth.repository.mjs +1 -1
- package/dist/src/modules/auth/auth.trpc.d.cts +7 -7
- package/dist/src/modules/auth/auth.trpc.d.mts +7 -7
- package/dist/src/modules/auth/auth.utils.cjs +1 -1
- package/dist/src/modules/auth/auth.utils.mjs +1 -1
- package/dist/src/modules/base/base.db.cjs +61 -0
- package/dist/src/modules/base/base.db.cjs.map +1 -0
- package/dist/src/modules/base/base.db.d.cts +33 -0
- package/dist/src/modules/base/base.db.d.mts +33 -0
- package/dist/src/modules/base/base.db.mjs +50 -0
- package/dist/src/modules/base/base.db.mjs.map +1 -0
- package/dist/src/modules/base/base.procedure.cjs +30 -0
- package/dist/src/modules/base/base.procedure.cjs.map +1 -1
- package/dist/src/modules/base/base.procedure.d.cts +14 -1
- package/dist/src/modules/base/base.procedure.d.mts +14 -1
- package/dist/src/modules/base/base.procedure.mjs +30 -0
- package/dist/src/modules/base/base.procedure.mjs.map +1 -1
- package/dist/src/modules/base/base.repository.d.mts +1 -1
- package/dist/src/modules/base/base.service.cjs.map +1 -1
- package/dist/src/modules/base/base.service.d.cts +2 -2
- package/dist/src/modules/base/base.service.d.mts +2 -2
- package/dist/src/modules/base/base.service.mjs.map +1 -1
- package/dist/src/modules/billing/billing.repository.d.cts +11 -11
- package/dist/src/modules/billing/billing.repository.d.mts +12 -12
- package/dist/src/modules/billing/billing.service.d.cts +7 -7
- package/dist/src/modules/billing/billing.service.d.mts +7 -7
- package/dist/src/modules/connect/connect.dto.d.cts +4 -4
- package/dist/src/modules/connect/connect.dto.d.mts +4 -4
- package/dist/src/modules/connect/connect.repository.d.cts +4 -4
- package/dist/src/modules/connect/connect.repository.d.mts +5 -5
- package/dist/src/modules/connect/connect.service.d.cts +8 -8
- package/dist/src/modules/connect/connect.service.d.mts +8 -8
- package/dist/src/modules/connect/connect.trpc.d.cts +1 -1
- package/dist/src/modules/connect/connect.trpc.d.mts +1 -1
- package/dist/src/modules/docx/docx.service.cjs +2 -1
- package/dist/src/modules/docx/docx.service.cjs.map +1 -1
- package/dist/src/modules/docx/docx.service.mjs +2 -1
- package/dist/src/modules/docx/docx.service.mjs.map +1 -1
- package/dist/src/modules/file/file.service.cjs +1 -1
- package/dist/src/modules/file/file.service.mjs +1 -1
- package/dist/src/modules/pdf/pdf.service.cjs +17 -0
- package/dist/src/modules/pdf/pdf.service.cjs.map +1 -0
- package/dist/src/modules/pdf/pdf.service.d.cts +10 -0
- package/dist/src/modules/pdf/pdf.service.d.mts +10 -0
- package/dist/src/modules/pdf/pdf.service.mjs +15 -0
- package/dist/src/modules/pdf/pdf.service.mjs.map +1 -0
- package/dist/src/modules/recurrence/recurrence.repository.d.mts +1 -1
- package/dist/src/modules/recurrence/recurrence.service.d.cts +4 -4
- package/dist/src/modules/recurrence/recurrence.service.d.mts +4 -4
- package/dist/src/modules/recurrence/recurrence.trpc.d.cts +3 -3
- package/dist/src/modules/recurrence/recurrence.trpc.d.mts +3 -3
- package/dist/src/modules/tag/tag.dto.d.mts +1 -1
- package/dist/src/modules/tag/tag.trpc.d.cts +2 -2
- package/dist/src/modules/tag/tag.trpc.d.mts +2 -2
- package/dist/src/modules/utils/getGlobalSearchCondition.d.mts +1 -1
- package/dist/src/modules/video/video.service.cjs +1 -1
- package/dist/src/modules/video/video.service.mjs +1 -1
- package/dist/src/types.d.cts +7 -7
- package/dist/src/types.d.mts +7 -7
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.service.cjs","names":["Base","createServiceProcedureBuilder","validateActor","createPermissionServiceProcedureBuilder","checkPermissionSync","checkPermissionAsync"],"sources":["../../../../src/modules/base/base.service.ts"],"sourcesContent":["import type { QueryFilter, QueryInput } from \"@m5kdev/commons/modules/schemas/query.schema\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport { Base } from \"./base.abstract\";\r\nimport { type AuthenticatedActor, validateActor } from \"./base.actor\";\r\nimport type { ServerResult, ServerResultAsync } from \"./base.dto\";\r\nimport {\r\n checkPermissionAsync,\r\n checkPermissionSync,\r\n type Entity,\r\n type ResourceActionGrant,\r\n type ResourceGrant,\r\n} from \"./base.grants\";\r\nimport {\r\n createPermissionServiceProcedureBuilder,\r\n createServiceProcedureBuilder,\r\n type PermissionServiceProcedureBuilder,\r\n type ServiceProcedureBuilder,\r\n type ServiceProcedureContext,\r\n} from \"./base.procedure\";\r\n\r\nexport type {\r\n PermissionServiceProcedureBuilder,\r\n ServiceProcedure,\r\n ServiceProcedureAccessConfig,\r\n ServiceProcedureAccessEntitiesConfig,\r\n ServiceProcedureAccessStateConfig,\r\n ServiceProcedureArgs,\r\n ServiceProcedureBuilder,\r\n ServiceProcedureContext,\r\n ServiceProcedureContextFilteredInput,\r\n ServiceProcedureContextFilterScope,\r\n ServiceProcedureEntityStepName,\r\n ServiceProcedureInputMapper,\r\n} from \"./base.procedure\";\r\n\r\nexport class BaseService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends Base {\r\n constructor(\r\n public repository: Repositories = {} as Repositories,\r\n public service: Services = {} as Services\r\n ) {\r\n super(\"service\");\r\n this.repository = repository;\r\n this.service = service;\r\n }\r\n\r\n addUserFilter(\r\n value: string,\r\n query?: undefined,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): QueryInput;\r\n addUserFilter<TQuery extends QueryInput>(\r\n value: string,\r\n query: TQuery,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): TQuery;\r\n addUserFilter(\r\n value: string,\r\n query?: QueryInput,\r\n columnId = \"userId\",\r\n method: QueryFilter[\"method\"] = \"equals\"\r\n ): QueryInput {\r\n const userFilter: QueryFilter = {\r\n columnId,\r\n type: \"string\",\r\n method,\r\n value,\r\n };\r\n return query\r\n ? { ...query, filters: [...(query?.filters ?? []), userFilter] }\r\n : { filters: [userFilter] };\r\n }\r\n\r\n protected procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): ServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include?: { user?: boolean; organization?: boolean; team?: boolean },\r\n query?: undefined,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): QueryInput;\r\n addContextFilter<TQuery extends QueryInput>(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } | undefined,\r\n query: TQuery,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): TQuery;\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } = {\r\n user: true,\r\n organization: false,\r\n team: false,\r\n },\r\n query?: QueryInput,\r\n map: Record<string, { columnId: string; method: QueryFilter[\"method\"] }> = {\r\n userId: {\r\n columnId: \"userId\",\r\n method: \"equals\",\r\n },\r\n organizationId: {\r\n columnId: \"organizationId\",\r\n method: \"equals\",\r\n },\r\n teamId: {\r\n columnId: \"teamId\",\r\n method: \"equals\",\r\n },\r\n }\r\n ): QueryInput {\r\n const filters: QueryFilter[] = [];\r\n\r\n if (include.user) {\r\n filters.push({\r\n columnId: map.userId.columnId,\r\n type: \"string\",\r\n method: map.userId.method,\r\n value: actor.userId,\r\n });\r\n }\r\n if (include.organization) {\r\n if (!validateActor(actor, \"organization\")) {\r\n throw new Error(\"Organization-scoped context filter requires an organization actor\");\r\n }\r\n filters.push({\r\n columnId: map.organizationId.columnId,\r\n type: \"string\",\r\n method: map.organizationId.method,\r\n value: actor.organizationId!,\r\n });\r\n }\r\n if (include.team) {\r\n if (!validateActor(actor, \"team\")) {\r\n throw new Error(\"Team-scoped context filter requires a team actor\");\r\n }\r\n filters.push({\r\n columnId: map.teamId.columnId,\r\n type: \"string\",\r\n method: map.teamId.method,\r\n value: actor.teamId!,\r\n });\r\n }\r\n return query ? { ...query, filters: [...(query?.filters ?? []), ...filters] } : { filters };\r\n }\r\n}\r\n\r\nexport class BasePermissionService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends BaseService<Repositories, Services, DefaultContext> {\r\n grants: ResourceGrant[];\r\n constructor(repository: Repositories, service: Services, grants: ResourceGrant[] = []) {\r\n super(repository, service);\r\n this.grants = grants;\r\n }\r\n\r\n accessGuard<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): ServerResult<true> {\r\n const hasPermission = this.checkPermission(actor, action, entities, grants);\r\n if (!hasPermission) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n async accessGuardAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<true> {\r\n const hasPermission = await this.checkPermissionAsync(actor, action, getEntities, grants);\r\n if (hasPermission.isErr()) return err(hasPermission.error);\r\n if (!hasPermission.value) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n protected override procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): PermissionServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createPermissionServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n checkPermission<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): boolean {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n return checkPermissionSync(actor, actionGrants, entities);\r\n }\r\n\r\n async checkPermissionAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<boolean> {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n const permission = await checkPermissionAsync(actor, actionGrants, getEntities);\r\n if (permission.isErr())\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Failed to check permission\", {\r\n cause: permission.error,\r\n });\r\n return ok(permission.value);\r\n }\r\n}\r\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"base.service.cjs","names":["Base","createServiceProcedureBuilder","validateActor","createPermissionServiceProcedureBuilder","checkPermissionSync","checkPermissionAsync"],"sources":["../../../../src/modules/base/base.service.ts"],"sourcesContent":["import type { QueryFilter, QueryInput } from \"@m5kdev/commons/modules/schemas/query.schema\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport { Base } from \"./base.abstract\";\r\nimport { type AuthenticatedActor, validateActor } from \"./base.actor\";\r\nimport type { ServerResult, ServerResultAsync } from \"./base.dto\";\r\nimport {\r\n checkPermissionAsync,\r\n checkPermissionSync,\r\n type Entity,\r\n type ResourceActionGrant,\r\n type ResourceGrant,\r\n} from \"./base.grants\";\r\nimport {\r\n createPermissionServiceProcedureBuilder,\r\n createServiceProcedureBuilder,\r\n type PermissionServiceProcedureBuilder,\r\n type ServiceProcedureBuilder,\r\n type ServiceProcedureContext,\r\n} from \"./base.procedure\";\r\n\r\nexport type {\r\n PermissionServiceProcedureBuilder,\r\n ServiceProcedure,\r\n ServiceProcedureAccessConfig,\r\n ServiceProcedureAccessEntitiesConfig,\r\n ServiceProcedureAccessStateConfig,\r\n ServiceProcedureArgs,\r\n ServiceProcedureBuilder,\r\n ServiceProcedureContext,\r\n ServiceProcedureContextFilteredInput,\r\n ServiceProcedureContextFilterScope,\r\n ServiceProcedureEntityStepName,\r\n ServiceProcedureInputMapper,\r\n ServiceProcedureLoadedResource,\r\n} from \"./base.procedure\";\r\n\r\nexport class BaseService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends Base {\r\n constructor(\r\n public repository: Repositories = {} as Repositories,\r\n public service: Services = {} as Services\r\n ) {\r\n super(\"service\");\r\n this.repository = repository;\r\n this.service = service;\r\n }\r\n\r\n addUserFilter(\r\n value: string,\r\n query?: undefined,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): QueryInput;\r\n addUserFilter<TQuery extends QueryInput>(\r\n value: string,\r\n query: TQuery,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): TQuery;\r\n addUserFilter(\r\n value: string,\r\n query?: QueryInput,\r\n columnId = \"userId\",\r\n method: QueryFilter[\"method\"] = \"equals\"\r\n ): QueryInput {\r\n const userFilter: QueryFilter = {\r\n columnId,\r\n type: \"string\",\r\n method,\r\n value,\r\n };\r\n return query\r\n ? { ...query, filters: [...(query?.filters ?? []), userFilter] }\r\n : { filters: [userFilter] };\r\n }\r\n\r\n protected procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): ServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include?: { user?: boolean; organization?: boolean; team?: boolean },\r\n query?: undefined,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): QueryInput;\r\n addContextFilter<TQuery extends QueryInput>(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } | undefined,\r\n query: TQuery,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): TQuery;\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } = {\r\n user: true,\r\n organization: false,\r\n team: false,\r\n },\r\n query?: QueryInput,\r\n map: Record<string, { columnId: string; method: QueryFilter[\"method\"] }> = {\r\n userId: {\r\n columnId: \"userId\",\r\n method: \"equals\",\r\n },\r\n organizationId: {\r\n columnId: \"organizationId\",\r\n method: \"equals\",\r\n },\r\n teamId: {\r\n columnId: \"teamId\",\r\n method: \"equals\",\r\n },\r\n }\r\n ): QueryInput {\r\n const filters: QueryFilter[] = [];\r\n\r\n if (include.user) {\r\n filters.push({\r\n columnId: map.userId.columnId,\r\n type: \"string\",\r\n method: map.userId.method,\r\n value: actor.userId,\r\n });\r\n }\r\n if (include.organization) {\r\n if (!validateActor(actor, \"organization\")) {\r\n throw new Error(\"Organization-scoped context filter requires an organization actor\");\r\n }\r\n filters.push({\r\n columnId: map.organizationId.columnId,\r\n type: \"string\",\r\n method: map.organizationId.method,\r\n value: actor.organizationId!,\r\n });\r\n }\r\n if (include.team) {\r\n if (!validateActor(actor, \"team\")) {\r\n throw new Error(\"Team-scoped context filter requires a team actor\");\r\n }\r\n filters.push({\r\n columnId: map.teamId.columnId,\r\n type: \"string\",\r\n method: map.teamId.method,\r\n value: actor.teamId!,\r\n });\r\n }\r\n return query ? { ...query, filters: [...(query?.filters ?? []), ...filters] } : { filters };\r\n }\r\n}\r\n\r\nexport class BasePermissionService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends BaseService<Repositories, Services, DefaultContext> {\r\n grants: ResourceGrant[];\r\n constructor(repository: Repositories, service: Services, grants: ResourceGrant[] = []) {\r\n super(repository, service);\r\n this.grants = grants;\r\n }\r\n\r\n accessGuard<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): ServerResult<true> {\r\n const hasPermission = this.checkPermission(actor, action, entities, grants);\r\n if (!hasPermission) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n async accessGuardAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<true> {\r\n const hasPermission = await this.checkPermissionAsync(actor, action, getEntities, grants);\r\n if (hasPermission.isErr()) return err(hasPermission.error);\r\n if (!hasPermission.value) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n protected override procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): PermissionServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createPermissionServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n checkPermission<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): boolean {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n return checkPermissionSync(actor, actionGrants, entities);\r\n }\r\n\r\n async checkPermissionAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<boolean> {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n const permission = await checkPermissionAsync(actor, actionGrants, getEntities);\r\n if (permission.isErr())\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Failed to check permission\", {\r\n cause: permission.error,\r\n });\r\n return ok(permission.value);\r\n }\r\n}\r\n"],"mappings":"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"}
|
|
@@ -2,7 +2,7 @@ import { ServerResult, ServerResultAsync } from "./base.dto.cjs";
|
|
|
2
2
|
import { Base } from "./base.abstract.cjs";
|
|
3
3
|
import { AuthenticatedActor } from "./base.actor.cjs";
|
|
4
4
|
import { Entity, ResourceActionGrant, ResourceGrant } from "./base.grants.cjs";
|
|
5
|
-
import { PermissionServiceProcedureBuilder, ServiceProcedure, ServiceProcedureAccessConfig, ServiceProcedureAccessEntitiesConfig, ServiceProcedureAccessStateConfig, ServiceProcedureArgs, ServiceProcedureBuilder, ServiceProcedureContext, ServiceProcedureContextFilterScope, ServiceProcedureContextFilteredInput, ServiceProcedureEntityStepName, ServiceProcedureInputMapper } from "./base.procedure.cjs";
|
|
5
|
+
import { PermissionServiceProcedureBuilder, ServiceProcedure, ServiceProcedureAccessConfig, ServiceProcedureAccessEntitiesConfig, ServiceProcedureAccessStateConfig, ServiceProcedureArgs, ServiceProcedureBuilder, ServiceProcedureContext, ServiceProcedureContextFilterScope, ServiceProcedureContextFilteredInput, ServiceProcedureEntityStepName, ServiceProcedureInputMapper, ServiceProcedureLoadedResource } from "./base.procedure.cjs";
|
|
6
6
|
import { QueryFilter, QueryInput } from "@m5kdev/commons/modules/schemas/query.schema";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/base/base.service.d.ts
|
|
@@ -40,5 +40,5 @@ declare class BasePermissionService<Repositories extends Record<string, Base>, S
|
|
|
40
40
|
checkPermissionAsync<T extends Entity>(actor: AuthenticatedActor, action: string, getEntities: () => ServerResultAsync<T | T[] | undefined>, grants?: ResourceActionGrant[]): ServerResultAsync<boolean>;
|
|
41
41
|
}
|
|
42
42
|
//#endregion
|
|
43
|
-
export { BasePermissionService, BaseService, type PermissionServiceProcedureBuilder, type ServiceProcedure, type ServiceProcedureAccessConfig, type ServiceProcedureAccessEntitiesConfig, type ServiceProcedureAccessStateConfig, type ServiceProcedureArgs, type ServiceProcedureBuilder, type ServiceProcedureContext, type ServiceProcedureContextFilterScope, type ServiceProcedureContextFilteredInput, type ServiceProcedureEntityStepName, type ServiceProcedureInputMapper };
|
|
43
|
+
export { BasePermissionService, BaseService, type PermissionServiceProcedureBuilder, type ServiceProcedure, type ServiceProcedureAccessConfig, type ServiceProcedureAccessEntitiesConfig, type ServiceProcedureAccessStateConfig, type ServiceProcedureArgs, type ServiceProcedureBuilder, type ServiceProcedureContext, type ServiceProcedureContextFilterScope, type ServiceProcedureContextFilteredInput, type ServiceProcedureEntityStepName, type ServiceProcedureInputMapper, type ServiceProcedureLoadedResource };
|
|
44
44
|
//# sourceMappingURL=base.service.d.cts.map
|
|
@@ -2,7 +2,7 @@ import { ServerResult, ServerResultAsync } from "./base.dto.mjs";
|
|
|
2
2
|
import { Base } from "./base.abstract.mjs";
|
|
3
3
|
import { AuthenticatedActor } from "./base.actor.mjs";
|
|
4
4
|
import { Entity, ResourceActionGrant, ResourceGrant } from "./base.grants.mjs";
|
|
5
|
-
import { PermissionServiceProcedureBuilder, ServiceProcedure, ServiceProcedureAccessConfig, ServiceProcedureAccessEntitiesConfig, ServiceProcedureAccessStateConfig, ServiceProcedureArgs, ServiceProcedureBuilder, ServiceProcedureContext, ServiceProcedureContextFilterScope, ServiceProcedureContextFilteredInput, ServiceProcedureEntityStepName, ServiceProcedureInputMapper } from "./base.procedure.mjs";
|
|
5
|
+
import { PermissionServiceProcedureBuilder, ServiceProcedure, ServiceProcedureAccessConfig, ServiceProcedureAccessEntitiesConfig, ServiceProcedureAccessStateConfig, ServiceProcedureArgs, ServiceProcedureBuilder, ServiceProcedureContext, ServiceProcedureContextFilterScope, ServiceProcedureContextFilteredInput, ServiceProcedureEntityStepName, ServiceProcedureInputMapper, ServiceProcedureLoadedResource } from "./base.procedure.mjs";
|
|
6
6
|
import { QueryFilter, QueryInput } from "@m5kdev/commons/modules/schemas/query.schema";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/base/base.service.d.ts
|
|
@@ -40,5 +40,5 @@ declare class BasePermissionService<Repositories extends Record<string, Base>, S
|
|
|
40
40
|
checkPermissionAsync<T extends Entity>(actor: AuthenticatedActor, action: string, getEntities: () => ServerResultAsync<T | T[] | undefined>, grants?: ResourceActionGrant[]): ServerResultAsync<boolean>;
|
|
41
41
|
}
|
|
42
42
|
//#endregion
|
|
43
|
-
export { BasePermissionService, BaseService, type PermissionServiceProcedureBuilder, type ServiceProcedure, type ServiceProcedureAccessConfig, type ServiceProcedureAccessEntitiesConfig, type ServiceProcedureAccessStateConfig, type ServiceProcedureArgs, type ServiceProcedureBuilder, type ServiceProcedureContext, type ServiceProcedureContextFilterScope, type ServiceProcedureContextFilteredInput, type ServiceProcedureEntityStepName, type ServiceProcedureInputMapper };
|
|
43
|
+
export { BasePermissionService, BaseService, type PermissionServiceProcedureBuilder, type ServiceProcedure, type ServiceProcedureAccessConfig, type ServiceProcedureAccessEntitiesConfig, type ServiceProcedureAccessStateConfig, type ServiceProcedureArgs, type ServiceProcedureBuilder, type ServiceProcedureContext, type ServiceProcedureContextFilterScope, type ServiceProcedureContextFilteredInput, type ServiceProcedureEntityStepName, type ServiceProcedureInputMapper, type ServiceProcedureLoadedResource };
|
|
44
44
|
//# sourceMappingURL=base.service.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.service.mjs","names":[],"sources":["../../../../src/modules/base/base.service.ts"],"sourcesContent":["import type { QueryFilter, QueryInput } from \"@m5kdev/commons/modules/schemas/query.schema\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport { Base } from \"./base.abstract\";\r\nimport { type AuthenticatedActor, validateActor } from \"./base.actor\";\r\nimport type { ServerResult, ServerResultAsync } from \"./base.dto\";\r\nimport {\r\n checkPermissionAsync,\r\n checkPermissionSync,\r\n type Entity,\r\n type ResourceActionGrant,\r\n type ResourceGrant,\r\n} from \"./base.grants\";\r\nimport {\r\n createPermissionServiceProcedureBuilder,\r\n createServiceProcedureBuilder,\r\n type PermissionServiceProcedureBuilder,\r\n type ServiceProcedureBuilder,\r\n type ServiceProcedureContext,\r\n} from \"./base.procedure\";\r\n\r\nexport type {\r\n PermissionServiceProcedureBuilder,\r\n ServiceProcedure,\r\n ServiceProcedureAccessConfig,\r\n ServiceProcedureAccessEntitiesConfig,\r\n ServiceProcedureAccessStateConfig,\r\n ServiceProcedureArgs,\r\n ServiceProcedureBuilder,\r\n ServiceProcedureContext,\r\n ServiceProcedureContextFilteredInput,\r\n ServiceProcedureContextFilterScope,\r\n ServiceProcedureEntityStepName,\r\n ServiceProcedureInputMapper,\r\n} from \"./base.procedure\";\r\n\r\nexport class BaseService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends Base {\r\n constructor(\r\n public repository: Repositories = {} as Repositories,\r\n public service: Services = {} as Services\r\n ) {\r\n super(\"service\");\r\n this.repository = repository;\r\n this.service = service;\r\n }\r\n\r\n addUserFilter(\r\n value: string,\r\n query?: undefined,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): QueryInput;\r\n addUserFilter<TQuery extends QueryInput>(\r\n value: string,\r\n query: TQuery,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): TQuery;\r\n addUserFilter(\r\n value: string,\r\n query?: QueryInput,\r\n columnId = \"userId\",\r\n method: QueryFilter[\"method\"] = \"equals\"\r\n ): QueryInput {\r\n const userFilter: QueryFilter = {\r\n columnId,\r\n type: \"string\",\r\n method,\r\n value,\r\n };\r\n return query\r\n ? { ...query, filters: [...(query?.filters ?? []), userFilter] }\r\n : { filters: [userFilter] };\r\n }\r\n\r\n protected procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): ServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include?: { user?: boolean; organization?: boolean; team?: boolean },\r\n query?: undefined,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): QueryInput;\r\n addContextFilter<TQuery extends QueryInput>(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } | undefined,\r\n query: TQuery,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): TQuery;\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } = {\r\n user: true,\r\n organization: false,\r\n team: false,\r\n },\r\n query?: QueryInput,\r\n map: Record<string, { columnId: string; method: QueryFilter[\"method\"] }> = {\r\n userId: {\r\n columnId: \"userId\",\r\n method: \"equals\",\r\n },\r\n organizationId: {\r\n columnId: \"organizationId\",\r\n method: \"equals\",\r\n },\r\n teamId: {\r\n columnId: \"teamId\",\r\n method: \"equals\",\r\n },\r\n }\r\n ): QueryInput {\r\n const filters: QueryFilter[] = [];\r\n\r\n if (include.user) {\r\n filters.push({\r\n columnId: map.userId.columnId,\r\n type: \"string\",\r\n method: map.userId.method,\r\n value: actor.userId,\r\n });\r\n }\r\n if (include.organization) {\r\n if (!validateActor(actor, \"organization\")) {\r\n throw new Error(\"Organization-scoped context filter requires an organization actor\");\r\n }\r\n filters.push({\r\n columnId: map.organizationId.columnId,\r\n type: \"string\",\r\n method: map.organizationId.method,\r\n value: actor.organizationId!,\r\n });\r\n }\r\n if (include.team) {\r\n if (!validateActor(actor, \"team\")) {\r\n throw new Error(\"Team-scoped context filter requires a team actor\");\r\n }\r\n filters.push({\r\n columnId: map.teamId.columnId,\r\n type: \"string\",\r\n method: map.teamId.method,\r\n value: actor.teamId!,\r\n });\r\n }\r\n return query ? { ...query, filters: [...(query?.filters ?? []), ...filters] } : { filters };\r\n }\r\n}\r\n\r\nexport class BasePermissionService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends BaseService<Repositories, Services, DefaultContext> {\r\n grants: ResourceGrant[];\r\n constructor(repository: Repositories, service: Services, grants: ResourceGrant[] = []) {\r\n super(repository, service);\r\n this.grants = grants;\r\n }\r\n\r\n accessGuard<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): ServerResult<true> {\r\n const hasPermission = this.checkPermission(actor, action, entities, grants);\r\n if (!hasPermission) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n async accessGuardAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<true> {\r\n const hasPermission = await this.checkPermissionAsync(actor, action, getEntities, grants);\r\n if (hasPermission.isErr()) return err(hasPermission.error);\r\n if (!hasPermission.value) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n protected override procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): PermissionServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createPermissionServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n checkPermission<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): boolean {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n return checkPermissionSync(actor, actionGrants, entities);\r\n }\r\n\r\n async checkPermissionAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<boolean> {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n const permission = await checkPermissionAsync(actor, actionGrants, getEntities);\r\n if (permission.isErr())\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Failed to check permission\", {\r\n cause: permission.error,\r\n });\r\n return ok(permission.value);\r\n }\r\n}\r\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"base.service.mjs","names":[],"sources":["../../../../src/modules/base/base.service.ts"],"sourcesContent":["import type { QueryFilter, QueryInput } from \"@m5kdev/commons/modules/schemas/query.schema\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport { Base } from \"./base.abstract\";\r\nimport { type AuthenticatedActor, validateActor } from \"./base.actor\";\r\nimport type { ServerResult, ServerResultAsync } from \"./base.dto\";\r\nimport {\r\n checkPermissionAsync,\r\n checkPermissionSync,\r\n type Entity,\r\n type ResourceActionGrant,\r\n type ResourceGrant,\r\n} from \"./base.grants\";\r\nimport {\r\n createPermissionServiceProcedureBuilder,\r\n createServiceProcedureBuilder,\r\n type PermissionServiceProcedureBuilder,\r\n type ServiceProcedureBuilder,\r\n type ServiceProcedureContext,\r\n} from \"./base.procedure\";\r\n\r\nexport type {\r\n PermissionServiceProcedureBuilder,\r\n ServiceProcedure,\r\n ServiceProcedureAccessConfig,\r\n ServiceProcedureAccessEntitiesConfig,\r\n ServiceProcedureAccessStateConfig,\r\n ServiceProcedureArgs,\r\n ServiceProcedureBuilder,\r\n ServiceProcedureContext,\r\n ServiceProcedureContextFilteredInput,\r\n ServiceProcedureContextFilterScope,\r\n ServiceProcedureEntityStepName,\r\n ServiceProcedureInputMapper,\r\n ServiceProcedureLoadedResource,\r\n} from \"./base.procedure\";\r\n\r\nexport class BaseService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends Base {\r\n constructor(\r\n public repository: Repositories = {} as Repositories,\r\n public service: Services = {} as Services\r\n ) {\r\n super(\"service\");\r\n this.repository = repository;\r\n this.service = service;\r\n }\r\n\r\n addUserFilter(\r\n value: string,\r\n query?: undefined,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): QueryInput;\r\n addUserFilter<TQuery extends QueryInput>(\r\n value: string,\r\n query: TQuery,\r\n columnId?: string,\r\n method?: QueryFilter[\"method\"]\r\n ): TQuery;\r\n addUserFilter(\r\n value: string,\r\n query?: QueryInput,\r\n columnId = \"userId\",\r\n method: QueryFilter[\"method\"] = \"equals\"\r\n ): QueryInput {\r\n const userFilter: QueryFilter = {\r\n columnId,\r\n type: \"string\",\r\n method,\r\n value,\r\n };\r\n return query\r\n ? { ...query, filters: [...(query?.filters ?? []), userFilter] }\r\n : { filters: [userFilter] };\r\n }\r\n\r\n protected procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): ServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include?: { user?: boolean; organization?: boolean; team?: boolean },\r\n query?: undefined,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): QueryInput;\r\n addContextFilter<TQuery extends QueryInput>(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } | undefined,\r\n query: TQuery,\r\n map?: Record<string, { columnId: string; method: QueryFilter[\"method\"] }>\r\n ): TQuery;\r\n addContextFilter(\r\n actor: AuthenticatedActor,\r\n include: { user?: boolean; organization?: boolean; team?: boolean } = {\r\n user: true,\r\n organization: false,\r\n team: false,\r\n },\r\n query?: QueryInput,\r\n map: Record<string, { columnId: string; method: QueryFilter[\"method\"] }> = {\r\n userId: {\r\n columnId: \"userId\",\r\n method: \"equals\",\r\n },\r\n organizationId: {\r\n columnId: \"organizationId\",\r\n method: \"equals\",\r\n },\r\n teamId: {\r\n columnId: \"teamId\",\r\n method: \"equals\",\r\n },\r\n }\r\n ): QueryInput {\r\n const filters: QueryFilter[] = [];\r\n\r\n if (include.user) {\r\n filters.push({\r\n columnId: map.userId.columnId,\r\n type: \"string\",\r\n method: map.userId.method,\r\n value: actor.userId,\r\n });\r\n }\r\n if (include.organization) {\r\n if (!validateActor(actor, \"organization\")) {\r\n throw new Error(\"Organization-scoped context filter requires an organization actor\");\r\n }\r\n filters.push({\r\n columnId: map.organizationId.columnId,\r\n type: \"string\",\r\n method: map.organizationId.method,\r\n value: actor.organizationId!,\r\n });\r\n }\r\n if (include.team) {\r\n if (!validateActor(actor, \"team\")) {\r\n throw new Error(\"Team-scoped context filter requires a team actor\");\r\n }\r\n filters.push({\r\n columnId: map.teamId.columnId,\r\n type: \"string\",\r\n method: map.teamId.method,\r\n value: actor.teamId!,\r\n });\r\n }\r\n return query ? { ...query, filters: [...(query?.filters ?? []), ...filters] } : { filters };\r\n }\r\n}\r\n\r\nexport class BasePermissionService<\r\n Repositories extends Record<string, Base>,\r\n Services extends Record<string, Base>,\r\n DefaultContext extends ServiceProcedureContext = ServiceProcedureContext,\r\n> extends BaseService<Repositories, Services, DefaultContext> {\r\n grants: ResourceGrant[];\r\n constructor(repository: Repositories, service: Services, grants: ResourceGrant[] = []) {\r\n super(repository, service);\r\n this.grants = grants;\r\n }\r\n\r\n accessGuard<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): ServerResult<true> {\r\n const hasPermission = this.checkPermission(actor, action, entities, grants);\r\n if (!hasPermission) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n async accessGuardAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<true> {\r\n const hasPermission = await this.checkPermissionAsync(actor, action, getEntities, grants);\r\n if (hasPermission.isErr()) return err(hasPermission.error);\r\n if (!hasPermission.value) return this.error(\"FORBIDDEN\");\r\n return ok(true);\r\n }\r\n\r\n protected override procedure<TInput, TCtx extends ServiceProcedureContext = DefaultContext>(\r\n name: string\r\n ): PermissionServiceProcedureBuilder<TInput, TCtx, Repositories, Services> {\r\n return createPermissionServiceProcedureBuilder(this, { name, steps: [] });\r\n }\r\n\r\n checkPermission<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n entities?: T | T[],\r\n grants?: ResourceActionGrant[]\r\n ): boolean {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n return checkPermissionSync(actor, actionGrants, entities);\r\n }\r\n\r\n async checkPermissionAsync<T extends Entity>(\r\n actor: AuthenticatedActor,\r\n action: string,\r\n getEntities: () => ServerResultAsync<T | T[] | undefined>,\r\n grants?: ResourceActionGrant[]\r\n ): ServerResultAsync<boolean> {\r\n const actionGrants = grants ?? this.grants.filter((grant) => grant.action === action);\r\n const permission = await checkPermissionAsync(actor, actionGrants, getEntities);\r\n if (permission.isErr())\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Failed to check permission\", {\r\n cause: permission.error,\r\n });\r\n return ok(permission.value);\r\n }\r\n}\r\n"],"mappings":"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"}
|
|
@@ -4,7 +4,7 @@ import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
|
|
|
4
4
|
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
5
5
|
import { InferSelectModel } from "drizzle-orm";
|
|
6
6
|
import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
|
|
7
|
-
import { Stripe
|
|
7
|
+
import { Stripe } from "stripe";
|
|
8
8
|
import { StripePlan } from "@m5kdev/commons/modules/billing/billing.types";
|
|
9
9
|
|
|
10
10
|
//#region src/modules/billing/billing.repository.d.ts
|
|
@@ -2713,7 +2713,7 @@ declare const schema: {
|
|
|
2713
2713
|
type Schema = typeof schema;
|
|
2714
2714
|
type Orm = LibSQLDatabase<Schema>;
|
|
2715
2715
|
declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<string, never>, Schema["subscriptions"]> {
|
|
2716
|
-
stripe: Stripe
|
|
2716
|
+
stripe: Stripe;
|
|
2717
2717
|
plans: StripePlan[];
|
|
2718
2718
|
trial?: StripePlan;
|
|
2719
2719
|
constructor(options: {
|
|
@@ -2721,7 +2721,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2721
2721
|
schema: Schema;
|
|
2722
2722
|
table: Schema["subscriptions"];
|
|
2723
2723
|
libs: {
|
|
2724
|
-
stripe: Stripe
|
|
2724
|
+
stripe: Stripe;
|
|
2725
2725
|
};
|
|
2726
2726
|
config: {
|
|
2727
2727
|
trial?: StripePlan;
|
|
@@ -2730,7 +2730,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2730
2730
|
});
|
|
2731
2731
|
hasTrial(): boolean;
|
|
2732
2732
|
getPlanByPriceId(priceId: string): StripePlan | undefined;
|
|
2733
|
-
getCustomerByEmail(email: string): ServerResultAsync<Stripe
|
|
2733
|
+
getCustomerByEmail(email: string): ServerResultAsync<Stripe.Customer | null>;
|
|
2734
2734
|
getUserByCustomerId(customerId: string): ServerResultAsync<InferSelectModel<Schema["users"]> | null>;
|
|
2735
2735
|
createCustomer({
|
|
2736
2736
|
email,
|
|
@@ -2740,8 +2740,8 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2740
2740
|
email: string;
|
|
2741
2741
|
name?: string;
|
|
2742
2742
|
userId: string;
|
|
2743
|
-
}): ServerResultAsync<Stripe
|
|
2744
|
-
createTrialSubscription(customerId: string): ServerResultAsync<Stripe
|
|
2743
|
+
}): ServerResultAsync<Stripe.Customer>;
|
|
2744
|
+
createTrialSubscription(customerId: string): ServerResultAsync<Stripe.Subscription>;
|
|
2745
2745
|
createSubscription({
|
|
2746
2746
|
customerId,
|
|
2747
2747
|
priceId,
|
|
@@ -2752,7 +2752,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2752
2752
|
priceId: string;
|
|
2753
2753
|
quantity?: number;
|
|
2754
2754
|
trialDays?: number;
|
|
2755
|
-
}): ServerResultAsync<Stripe
|
|
2755
|
+
}): ServerResultAsync<Stripe.Subscription>;
|
|
2756
2756
|
updateUserCustomerId({
|
|
2757
2757
|
userId,
|
|
2758
2758
|
customerId
|
|
@@ -2762,7 +2762,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2762
2762
|
}): ServerResultAsync<InferSelectModel<Schema["users"]>>;
|
|
2763
2763
|
getLatestSubscription(referenceId: string): ServerResultAsync<BillingSchema | null>;
|
|
2764
2764
|
getActiveSubscription(referenceId: string): ServerResultAsync<BillingSchema | null>;
|
|
2765
|
-
listInvoices(customerId: string): ServerResultAsync<Stripe
|
|
2765
|
+
listInvoices(customerId: string): ServerResultAsync<Stripe.Invoice[]>;
|
|
2766
2766
|
createCheckoutSession({
|
|
2767
2767
|
customerId,
|
|
2768
2768
|
priceId,
|
|
@@ -2771,8 +2771,8 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2771
2771
|
customerId: string;
|
|
2772
2772
|
priceId: string;
|
|
2773
2773
|
userId: string;
|
|
2774
|
-
}): ServerResultAsync<Stripe
|
|
2775
|
-
createBillingPortalSession(customerId: string): ServerResultAsync<Stripe
|
|
2774
|
+
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
2775
|
+
createBillingPortalSession(customerId: string): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
2776
2776
|
syncStripeData({
|
|
2777
2777
|
customerId,
|
|
2778
2778
|
userId
|
|
@@ -2780,7 +2780,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2780
2780
|
customerId: string;
|
|
2781
2781
|
userId: string;
|
|
2782
2782
|
}): ServerResultAsync<boolean>;
|
|
2783
|
-
constructEvent(body: Buffer | string, signature: string, secret: string): ServerResult<Stripe
|
|
2783
|
+
constructEvent(body: Buffer | string, signature: string, secret: string): ServerResult<Stripe.Event>;
|
|
2784
2784
|
}
|
|
2785
2785
|
//#endregion
|
|
2786
2786
|
export { BillingRepository };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ServerResult, ServerResultAsync } from "../base/base.dto.mjs";
|
|
2
2
|
import { BaseTableRepository } from "../base/base.repository.mjs";
|
|
3
3
|
import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
|
|
4
|
-
import { InferSelectModel } from "drizzle-orm";
|
|
5
4
|
import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
|
|
5
|
+
import { InferSelectModel } from "drizzle-orm";
|
|
6
6
|
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
7
|
-
import { Stripe
|
|
7
|
+
import { Stripe } from "stripe";
|
|
8
8
|
import { StripePlan } from "@m5kdev/commons/modules/billing/billing.types";
|
|
9
9
|
|
|
10
10
|
//#region src/modules/billing/billing.repository.d.ts
|
|
@@ -2713,7 +2713,7 @@ declare const schema: {
|
|
|
2713
2713
|
type Schema = typeof schema;
|
|
2714
2714
|
type Orm = LibSQLDatabase<Schema>;
|
|
2715
2715
|
declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<string, never>, Schema["subscriptions"]> {
|
|
2716
|
-
stripe: Stripe
|
|
2716
|
+
stripe: Stripe;
|
|
2717
2717
|
plans: StripePlan[];
|
|
2718
2718
|
trial?: StripePlan;
|
|
2719
2719
|
constructor(options: {
|
|
@@ -2721,7 +2721,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2721
2721
|
schema: Schema;
|
|
2722
2722
|
table: Schema["subscriptions"];
|
|
2723
2723
|
libs: {
|
|
2724
|
-
stripe: Stripe
|
|
2724
|
+
stripe: Stripe;
|
|
2725
2725
|
};
|
|
2726
2726
|
config: {
|
|
2727
2727
|
trial?: StripePlan;
|
|
@@ -2730,7 +2730,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2730
2730
|
});
|
|
2731
2731
|
hasTrial(): boolean;
|
|
2732
2732
|
getPlanByPriceId(priceId: string): StripePlan | undefined;
|
|
2733
|
-
getCustomerByEmail(email: string): ServerResultAsync<Stripe
|
|
2733
|
+
getCustomerByEmail(email: string): ServerResultAsync<Stripe.Customer | null>;
|
|
2734
2734
|
getUserByCustomerId(customerId: string): ServerResultAsync<InferSelectModel<Schema["users"]> | null>;
|
|
2735
2735
|
createCustomer({
|
|
2736
2736
|
email,
|
|
@@ -2740,8 +2740,8 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2740
2740
|
email: string;
|
|
2741
2741
|
name?: string;
|
|
2742
2742
|
userId: string;
|
|
2743
|
-
}): ServerResultAsync<Stripe
|
|
2744
|
-
createTrialSubscription(customerId: string): ServerResultAsync<Stripe
|
|
2743
|
+
}): ServerResultAsync<Stripe.Customer>;
|
|
2744
|
+
createTrialSubscription(customerId: string): ServerResultAsync<Stripe.Subscription>;
|
|
2745
2745
|
createSubscription({
|
|
2746
2746
|
customerId,
|
|
2747
2747
|
priceId,
|
|
@@ -2752,7 +2752,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2752
2752
|
priceId: string;
|
|
2753
2753
|
quantity?: number;
|
|
2754
2754
|
trialDays?: number;
|
|
2755
|
-
}): ServerResultAsync<Stripe
|
|
2755
|
+
}): ServerResultAsync<Stripe.Subscription>;
|
|
2756
2756
|
updateUserCustomerId({
|
|
2757
2757
|
userId,
|
|
2758
2758
|
customerId
|
|
@@ -2762,7 +2762,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2762
2762
|
}): ServerResultAsync<InferSelectModel<Schema["users"]>>;
|
|
2763
2763
|
getLatestSubscription(referenceId: string): ServerResultAsync<BillingSchema | null>;
|
|
2764
2764
|
getActiveSubscription(referenceId: string): ServerResultAsync<BillingSchema | null>;
|
|
2765
|
-
listInvoices(customerId: string): ServerResultAsync<Stripe
|
|
2765
|
+
listInvoices(customerId: string): ServerResultAsync<Stripe.Invoice[]>;
|
|
2766
2766
|
createCheckoutSession({
|
|
2767
2767
|
customerId,
|
|
2768
2768
|
priceId,
|
|
@@ -2771,8 +2771,8 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2771
2771
|
customerId: string;
|
|
2772
2772
|
priceId: string;
|
|
2773
2773
|
userId: string;
|
|
2774
|
-
}): ServerResultAsync<Stripe
|
|
2775
|
-
createBillingPortalSession(customerId: string): ServerResultAsync<Stripe
|
|
2774
|
+
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
2775
|
+
createBillingPortalSession(customerId: string): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
2776
2776
|
syncStripeData({
|
|
2777
2777
|
customerId,
|
|
2778
2778
|
userId
|
|
@@ -2780,7 +2780,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2780
2780
|
customerId: string;
|
|
2781
2781
|
userId: string;
|
|
2782
2782
|
}): ServerResultAsync<boolean>;
|
|
2783
|
-
constructEvent(body: Buffer | string, signature: string, secret: string): ServerResult<Stripe
|
|
2783
|
+
constructEvent(body: Buffer | string, signature: string, secret: string): ServerResult<Stripe.Event>;
|
|
2784
2784
|
}
|
|
2785
2785
|
//#endregion
|
|
2786
2786
|
export { BillingRepository };
|
|
@@ -4,7 +4,7 @@ import { BillingRepository } from "./billing.repository.cjs";
|
|
|
4
4
|
import { User } from "../auth/auth.lib.cjs";
|
|
5
5
|
import { BaseService } from "../base/base.service.cjs";
|
|
6
6
|
import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
|
|
7
|
-
import Stripe from "stripe";
|
|
7
|
+
import Stripe$1 from "stripe";
|
|
8
8
|
|
|
9
9
|
//#region src/modules/billing/billing.service.d.ts
|
|
10
10
|
declare class BillingService extends BaseService<{
|
|
@@ -18,7 +18,7 @@ declare class BillingService extends BaseService<{
|
|
|
18
18
|
email: string;
|
|
19
19
|
name?: string;
|
|
20
20
|
};
|
|
21
|
-
}): ServerResultAsync<Stripe.Customer>;
|
|
21
|
+
}): ServerResultAsync<Stripe$1.Customer>;
|
|
22
22
|
createUserHook({
|
|
23
23
|
user
|
|
24
24
|
}: {
|
|
@@ -29,7 +29,7 @@ declare class BillingService extends BaseService<{
|
|
|
29
29
|
};
|
|
30
30
|
}): ServerResultAsync<boolean>;
|
|
31
31
|
getActiveSubscription(ctx: Context): ServerResultAsync<BillingSchema | null>;
|
|
32
|
-
listInvoices(ctx: Context): ServerResultAsync<Stripe.Invoice[]>;
|
|
32
|
+
listInvoices(ctx: Context): ServerResultAsync<Stripe$1.Invoice[]>;
|
|
33
33
|
createCheckoutSession({
|
|
34
34
|
priceId
|
|
35
35
|
}: {
|
|
@@ -38,15 +38,15 @@ declare class BillingService extends BaseService<{
|
|
|
38
38
|
user
|
|
39
39
|
}: {
|
|
40
40
|
user: User;
|
|
41
|
-
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
41
|
+
}): ServerResultAsync<Stripe$1.Checkout.Session>;
|
|
42
42
|
createBillingPortalSession({
|
|
43
43
|
user
|
|
44
44
|
}: {
|
|
45
45
|
user: User;
|
|
46
|
-
}): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
47
|
-
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe.Event>;
|
|
46
|
+
}): ServerResultAsync<Stripe$1.BillingPortal.Session>;
|
|
47
|
+
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe$1.Event>;
|
|
48
48
|
syncStripeData(customerId: string, eventType?: string): ServerResultAsync<boolean>;
|
|
49
|
-
processEvent(event: Stripe.Event): ServerResultAsync<boolean>;
|
|
49
|
+
processEvent(event: Stripe$1.Event): ServerResultAsync<boolean>;
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
export { BillingService };
|
|
@@ -4,7 +4,7 @@ import { BillingRepository } from "./billing.repository.mjs";
|
|
|
4
4
|
import { User } from "../auth/auth.lib.mjs";
|
|
5
5
|
import { BaseService } from "../base/base.service.mjs";
|
|
6
6
|
import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
|
|
7
|
-
import Stripe from "stripe";
|
|
7
|
+
import Stripe$1 from "stripe";
|
|
8
8
|
|
|
9
9
|
//#region src/modules/billing/billing.service.d.ts
|
|
10
10
|
declare class BillingService extends BaseService<{
|
|
@@ -18,7 +18,7 @@ declare class BillingService extends BaseService<{
|
|
|
18
18
|
email: string;
|
|
19
19
|
name?: string;
|
|
20
20
|
};
|
|
21
|
-
}): ServerResultAsync<Stripe.Customer>;
|
|
21
|
+
}): ServerResultAsync<Stripe$1.Customer>;
|
|
22
22
|
createUserHook({
|
|
23
23
|
user
|
|
24
24
|
}: {
|
|
@@ -29,7 +29,7 @@ declare class BillingService extends BaseService<{
|
|
|
29
29
|
};
|
|
30
30
|
}): ServerResultAsync<boolean>;
|
|
31
31
|
getActiveSubscription(ctx: Context): ServerResultAsync<BillingSchema | null>;
|
|
32
|
-
listInvoices(ctx: Context): ServerResultAsync<Stripe.Invoice[]>;
|
|
32
|
+
listInvoices(ctx: Context): ServerResultAsync<Stripe$1.Invoice[]>;
|
|
33
33
|
createCheckoutSession({
|
|
34
34
|
priceId
|
|
35
35
|
}: {
|
|
@@ -38,15 +38,15 @@ declare class BillingService extends BaseService<{
|
|
|
38
38
|
user
|
|
39
39
|
}: {
|
|
40
40
|
user: User;
|
|
41
|
-
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
41
|
+
}): ServerResultAsync<Stripe$1.Checkout.Session>;
|
|
42
42
|
createBillingPortalSession({
|
|
43
43
|
user
|
|
44
44
|
}: {
|
|
45
45
|
user: User;
|
|
46
|
-
}): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
47
|
-
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe.Event>;
|
|
46
|
+
}): ServerResultAsync<Stripe$1.BillingPortal.Session>;
|
|
47
|
+
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe$1.Event>;
|
|
48
48
|
syncStripeData(customerId: string, eventType?: string): ServerResultAsync<boolean>;
|
|
49
|
-
processEvent(event: Stripe.Event): ServerResultAsync<boolean>;
|
|
49
|
+
processEvent(event: Stripe$1.Event): ServerResultAsync<boolean>;
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
export { BillingService };
|
|
@@ -27,16 +27,16 @@ declare const connectSelectOutputSchema: z.ZodObject<{
|
|
|
27
27
|
id: z.ZodString;
|
|
28
28
|
createdAt: z.ZodDate;
|
|
29
29
|
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
30
|
-
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
31
30
|
userId: z.ZodString;
|
|
32
31
|
provider: z.ZodString;
|
|
32
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
33
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
34
|
accountType: z.ZodString;
|
|
34
35
|
providerAccountId: z.ZodString;
|
|
35
36
|
handle: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
36
37
|
displayName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
38
|
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
38
39
|
tokenType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
-
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
40
|
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
41
|
metadataJson: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
42
42
|
revokedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
@@ -51,16 +51,16 @@ declare const connectListOutputSchema: z.ZodArray<z.ZodObject<{
|
|
|
51
51
|
id: z.ZodString;
|
|
52
52
|
createdAt: z.ZodDate;
|
|
53
53
|
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
54
|
-
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
55
54
|
userId: z.ZodString;
|
|
56
55
|
provider: z.ZodString;
|
|
56
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
57
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
58
|
accountType: z.ZodString;
|
|
58
59
|
providerAccountId: z.ZodString;
|
|
59
60
|
handle: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
61
|
displayName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
61
62
|
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
62
63
|
tokenType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
-
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
64
|
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
65
65
|
metadataJson: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
66
66
|
revokedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
@@ -27,16 +27,16 @@ declare const connectSelectOutputSchema: z.ZodObject<{
|
|
|
27
27
|
id: z.ZodString;
|
|
28
28
|
createdAt: z.ZodDate;
|
|
29
29
|
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
30
|
-
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
31
30
|
userId: z.ZodString;
|
|
32
31
|
provider: z.ZodString;
|
|
32
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
33
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
34
|
accountType: z.ZodString;
|
|
34
35
|
providerAccountId: z.ZodString;
|
|
35
36
|
handle: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
36
37
|
displayName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
38
|
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
38
39
|
tokenType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
-
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
40
|
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
41
|
metadataJson: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
42
42
|
revokedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
@@ -51,16 +51,16 @@ declare const connectListOutputSchema: z.ZodArray<z.ZodObject<{
|
|
|
51
51
|
id: z.ZodString;
|
|
52
52
|
createdAt: z.ZodDate;
|
|
53
53
|
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
54
|
-
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
55
54
|
userId: z.ZodString;
|
|
56
55
|
provider: z.ZodString;
|
|
56
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
57
|
+
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
58
|
accountType: z.ZodString;
|
|
58
59
|
providerAccountId: z.ZodString;
|
|
59
60
|
handle: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
60
61
|
displayName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
61
62
|
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
62
63
|
tokenType: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
-
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
64
|
parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
65
65
|
metadataJson: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
|
|
66
66
|
revokedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
@@ -396,18 +396,18 @@ declare class ConnectRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
396
396
|
id: string;
|
|
397
397
|
createdAt: Date;
|
|
398
398
|
updatedAt: Date | null;
|
|
399
|
-
expiresAt: Date | null;
|
|
400
399
|
userId: string;
|
|
401
400
|
provider: string;
|
|
401
|
+
expiresAt: Date | null;
|
|
402
|
+
accessToken: string;
|
|
403
|
+
refreshToken: string | null;
|
|
404
|
+
scope: string | null;
|
|
402
405
|
accountType: string;
|
|
403
406
|
providerAccountId: string;
|
|
404
407
|
handle: string | null;
|
|
405
408
|
displayName: string | null;
|
|
406
409
|
avatarUrl: string | null;
|
|
407
|
-
accessToken: string;
|
|
408
|
-
refreshToken: string | null;
|
|
409
410
|
tokenType: string | null;
|
|
410
|
-
scope: string | null;
|
|
411
411
|
parentId: string | null;
|
|
412
412
|
metadataJson: unknown;
|
|
413
413
|
revokedAt: Date | null;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ServerResult } from "../base/base.dto.mjs";
|
|
2
2
|
import { BaseTableRepository } from "../base/base.repository.mjs";
|
|
3
3
|
import { ConnectListInputSchema } from "./connect.dto.mjs";
|
|
4
|
-
import { InferInsertModel, InferSelectModel } from "drizzle-orm";
|
|
5
4
|
import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
|
|
5
|
+
import { InferInsertModel, InferSelectModel } from "drizzle-orm";
|
|
6
6
|
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/connect/connect.repository.d.ts
|
|
@@ -396,18 +396,18 @@ declare class ConnectRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
396
396
|
id: string;
|
|
397
397
|
createdAt: Date;
|
|
398
398
|
updatedAt: Date | null;
|
|
399
|
-
expiresAt: Date | null;
|
|
400
399
|
userId: string;
|
|
401
400
|
provider: string;
|
|
401
|
+
expiresAt: Date | null;
|
|
402
|
+
accessToken: string;
|
|
403
|
+
refreshToken: string | null;
|
|
404
|
+
scope: string | null;
|
|
402
405
|
accountType: string;
|
|
403
406
|
providerAccountId: string;
|
|
404
407
|
handle: string | null;
|
|
405
408
|
displayName: string | null;
|
|
406
409
|
avatarUrl: string | null;
|
|
407
|
-
accessToken: string;
|
|
408
|
-
refreshToken: string | null;
|
|
409
410
|
tokenType: string | null;
|
|
410
|
-
scope: string | null;
|
|
411
411
|
parentId: string | null;
|
|
412
412
|
metadataJson: unknown;
|
|
413
413
|
revokedAt: Date | null;
|
|
@@ -22,18 +22,18 @@ declare class ConnectService extends BaseService<{
|
|
|
22
22
|
id: string;
|
|
23
23
|
createdAt: Date;
|
|
24
24
|
updatedAt: Date | null;
|
|
25
|
-
expiresAt: Date | null;
|
|
26
25
|
userId: string;
|
|
27
26
|
provider: string;
|
|
27
|
+
expiresAt: Date | null;
|
|
28
|
+
accessToken: string;
|
|
29
|
+
refreshToken: string | null;
|
|
30
|
+
scope: string | null;
|
|
28
31
|
accountType: string;
|
|
29
32
|
providerAccountId: string;
|
|
30
33
|
handle: string | null;
|
|
31
34
|
displayName: string | null;
|
|
32
35
|
avatarUrl: string | null;
|
|
33
|
-
accessToken: string;
|
|
34
|
-
refreshToken: string | null;
|
|
35
36
|
tokenType: string | null;
|
|
36
|
-
scope: string | null;
|
|
37
37
|
parentId: string | null;
|
|
38
38
|
metadataJson: unknown;
|
|
39
39
|
revokedAt: Date | null;
|
|
@@ -43,18 +43,18 @@ declare class ConnectService extends BaseService<{
|
|
|
43
43
|
id: string;
|
|
44
44
|
createdAt: Date;
|
|
45
45
|
updatedAt: Date | null;
|
|
46
|
-
expiresAt: Date | null;
|
|
47
46
|
userId: string;
|
|
48
47
|
provider: string;
|
|
48
|
+
expiresAt: Date | null;
|
|
49
|
+
accessToken: string;
|
|
50
|
+
refreshToken: string | null;
|
|
51
|
+
scope: string | null;
|
|
49
52
|
accountType: string;
|
|
50
53
|
providerAccountId: string;
|
|
51
54
|
handle: string | null;
|
|
52
55
|
displayName: string | null;
|
|
53
56
|
avatarUrl: string | null;
|
|
54
|
-
accessToken: string;
|
|
55
|
-
refreshToken: string | null;
|
|
56
57
|
tokenType: string | null;
|
|
57
|
-
scope: string | null;
|
|
58
58
|
parentId: string | null;
|
|
59
59
|
metadataJson: unknown;
|
|
60
60
|
revokedAt: Date | null;
|
|
@@ -22,18 +22,18 @@ declare class ConnectService extends BaseService<{
|
|
|
22
22
|
id: string;
|
|
23
23
|
createdAt: Date;
|
|
24
24
|
updatedAt: Date | null;
|
|
25
|
-
expiresAt: Date | null;
|
|
26
25
|
userId: string;
|
|
27
26
|
provider: string;
|
|
27
|
+
expiresAt: Date | null;
|
|
28
|
+
accessToken: string;
|
|
29
|
+
refreshToken: string | null;
|
|
30
|
+
scope: string | null;
|
|
28
31
|
accountType: string;
|
|
29
32
|
providerAccountId: string;
|
|
30
33
|
handle: string | null;
|
|
31
34
|
displayName: string | null;
|
|
32
35
|
avatarUrl: string | null;
|
|
33
|
-
accessToken: string;
|
|
34
|
-
refreshToken: string | null;
|
|
35
36
|
tokenType: string | null;
|
|
36
|
-
scope: string | null;
|
|
37
37
|
parentId: string | null;
|
|
38
38
|
metadataJson: unknown;
|
|
39
39
|
revokedAt: Date | null;
|
|
@@ -43,18 +43,18 @@ declare class ConnectService extends BaseService<{
|
|
|
43
43
|
id: string;
|
|
44
44
|
createdAt: Date;
|
|
45
45
|
updatedAt: Date | null;
|
|
46
|
-
expiresAt: Date | null;
|
|
47
46
|
userId: string;
|
|
48
47
|
provider: string;
|
|
48
|
+
expiresAt: Date | null;
|
|
49
|
+
accessToken: string;
|
|
50
|
+
refreshToken: string | null;
|
|
51
|
+
scope: string | null;
|
|
49
52
|
accountType: string;
|
|
50
53
|
providerAccountId: string;
|
|
51
54
|
handle: string | null;
|
|
52
55
|
displayName: string | null;
|
|
53
56
|
avatarUrl: string | null;
|
|
54
|
-
accessToken: string;
|
|
55
|
-
refreshToken: string | null;
|
|
56
57
|
tokenType: string | null;
|
|
57
|
-
scope: string | null;
|
|
58
58
|
parentId: string | null;
|
|
59
59
|
metadataJson: unknown;
|
|
60
60
|
revokedAt: Date | null;
|
|
@@ -26,11 +26,11 @@ declare function createConnectTRPC({
|
|
|
26
26
|
providerAccountId: string;
|
|
27
27
|
updatedAt?: Date | null | undefined;
|
|
28
28
|
expiresAt?: Date | null | undefined;
|
|
29
|
+
scope?: string | null | undefined;
|
|
29
30
|
handle?: string | null | undefined;
|
|
30
31
|
displayName?: string | null | undefined;
|
|
31
32
|
avatarUrl?: string | null | undefined;
|
|
32
33
|
tokenType?: string | null | undefined;
|
|
33
|
-
scope?: string | null | undefined;
|
|
34
34
|
parentId?: string | null | undefined;
|
|
35
35
|
metadataJson?: unknown;
|
|
36
36
|
revokedAt?: Date | null | undefined;
|