@qlover/create-app 1.0.1 → 1.1.0

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/index.cjs +9 -9
  3. package/dist/index.js +9 -9
  4. package/dist/templates/next-app/config/Identifier/api.ts +7 -0
  5. package/dist/templates/next-app/config/Identifier/pages/page.register.ts +8 -0
  6. package/dist/templates/next-app/config/common.ts +1 -1
  7. package/dist/templates/next-app/config/i18n/HomeI18n.ts +2 -0
  8. package/dist/templates/next-app/config/i18n/register18n.ts +2 -1
  9. package/dist/templates/next-app/config/route.ts +9 -0
  10. package/dist/templates/next-app/migrations/schema/UserSchema.ts +1 -1
  11. package/dist/templates/next-app/next.config.ts +5 -4
  12. package/dist/templates/next-app/package.json +7 -8
  13. package/dist/templates/next-app/public/locales/en.json +4 -1
  14. package/dist/templates/next-app/public/locales/zh.json +4 -1
  15. package/dist/templates/next-app/src/app/[locale]/auth/layout.tsx +18 -0
  16. package/dist/templates/next-app/src/app/[locale]/{login → auth/login}/LoginForm.tsx +2 -1
  17. package/dist/templates/next-app/src/app/[locale]/{login → auth/login}/page.tsx +4 -5
  18. package/dist/templates/next-app/src/app/[locale]/auth/page.tsx +8 -0
  19. package/dist/templates/next-app/src/app/[locale]/{register → auth/register}/RegisterForm.tsx +24 -3
  20. package/dist/templates/next-app/src/app/[locale]/{register → auth/register}/page.tsx +4 -5
  21. package/dist/templates/next-app/src/app/[locale]/page.tsx +18 -45
  22. package/dist/templates/next-app/src/app/api/ai/completions/route.ts +13 -13
  23. package/dist/templates/next-app/src/app/api/auth/callback/route.ts +11 -0
  24. package/dist/templates/next-app/src/app/api/callback/route.ts +49 -0
  25. package/dist/templates/next-app/src/base/cases/AppConfig.ts +2 -0
  26. package/dist/templates/next-app/src/base/cases/DialogErrorPlugin.ts +3 -6
  27. package/dist/templates/next-app/src/base/cases/DialogHandler.ts +0 -1
  28. package/dist/templates/next-app/src/base/cases/RequestEncryptPlugin.ts +13 -15
  29. package/dist/templates/next-app/src/base/cases/RouterService.ts +2 -7
  30. package/dist/templates/next-app/src/base/cases/StringEncryptor.ts +0 -6
  31. package/dist/templates/next-app/src/base/cases/TranslateI18nUtil.ts +53 -0
  32. package/dist/templates/next-app/src/base/cases/ZodColumnBuilder.ts +0 -10
  33. package/dist/templates/next-app/src/base/port/AdminLayoutInterface.ts +0 -3
  34. package/dist/templates/next-app/src/base/port/AppUserApiInterface.ts +1 -1
  35. package/dist/templates/next-app/src/base/port/I18nServiceInterface.ts +0 -18
  36. package/dist/templates/next-app/src/base/port/UserServiceInterface.ts +10 -5
  37. package/dist/templates/next-app/src/base/services/{appApi/AppApiRequester.ts → AppApiRequester.ts} +16 -11
  38. package/dist/templates/next-app/src/base/services/AppUserGateway.ts +110 -0
  39. package/dist/templates/next-app/src/base/services/I18nService.ts +1 -7
  40. package/dist/templates/next-app/src/base/services/ResourceService.ts +1 -4
  41. package/dist/templates/next-app/src/base/services/UserService.ts +28 -17
  42. package/dist/templates/next-app/src/base/services/adminApi/AdminLocalesApi.ts +5 -7
  43. package/dist/templates/next-app/src/base/services/adminApi/AdminUserApi.ts +4 -3
  44. package/dist/templates/next-app/src/base/services/appApi/AppApiPlugin.ts +24 -16
  45. package/dist/templates/next-app/src/base/services/appApi/AppUserApiBootstrap.ts +2 -5
  46. package/dist/templates/next-app/src/core/bootstraps/BootstrapServer.ts +15 -18
  47. package/dist/templates/next-app/src/core/clientIoc/ClientIOCRegister.ts +0 -5
  48. package/dist/templates/next-app/src/core/globals.ts +1 -0
  49. package/dist/templates/next-app/src/core/serverIoc/ServerIOCRegister.ts +2 -8
  50. package/dist/templates/next-app/src/i18n/routing.ts +8 -3
  51. package/dist/templates/next-app/src/lib/supabase/client.ts +8 -0
  52. package/dist/templates/next-app/src/lib/supabase/conts.ts +2 -0
  53. package/dist/templates/next-app/src/lib/supabase/proxy.ts +84 -0
  54. package/dist/templates/next-app/src/lib/supabase/server.ts +38 -0
  55. package/dist/templates/next-app/src/proxy.ts +8 -1
  56. package/dist/templates/next-app/src/server/AppPageRouteParams.ts +5 -2
  57. package/dist/templates/next-app/src/server/NextApiServer.ts +2 -9
  58. package/dist/templates/next-app/src/server/PagesRouteParams.ts +3 -4
  59. package/dist/templates/next-app/src/server/ServerAuth.ts +18 -12
  60. package/dist/templates/next-app/src/server/SupabaseBridge.ts +66 -59
  61. package/dist/templates/next-app/src/server/controllers/UserController.ts +7 -2
  62. package/dist/templates/next-app/src/server/port/ServerAuthInterface.ts +4 -0
  63. package/dist/templates/next-app/src/server/port/ServerInterface.ts +2 -1
  64. package/dist/templates/next-app/src/server/port/UserServiceInterface.ts +7 -1
  65. package/dist/templates/next-app/src/server/repositorys/LocalesRepository.ts +0 -3
  66. package/dist/templates/next-app/src/server/repositorys/UserRepository.ts +0 -3
  67. package/dist/templates/next-app/src/server/services/UserService.ts +71 -51
  68. package/dist/templates/next-app/src/server/validators/LocalesValidator.ts +0 -3
  69. package/dist/templates/next-app/src/server/validators/LoginValidator.ts +0 -6
  70. package/dist/templates/next-app/src/server/validators/SignupVerifyValidator.ts +68 -0
  71. package/dist/templates/next-app/src/uikit/components/BootstrapsProvider.tsx +3 -3
  72. package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportEvent.ts +0 -6
  73. package/dist/templates/next-app/src/uikit/components-app/AdminButton.tsx +29 -0
  74. package/dist/templates/next-app/src/uikit/components-app/AppRoutePage.tsx +21 -28
  75. package/dist/templates/next-app/src/uikit/components-app/AuthButton.tsx +20 -0
  76. package/dist/templates/next-app/src/uikit/hook/useI18nInterface.ts +2 -2
  77. package/dist/templates/next-app/src/uikit/hook/useWarnTranslations.ts +3 -17
  78. package/dist/templates/next-app/src/uikit/utils/getHashParams.ts +8 -0
  79. package/dist/templates/next-app/src/uikit/utils/getHashVerifyEmailParams.ts +42 -0
  80. package/dist/templates/react-app/config/i18n/PageI18nInterface.ts +2 -0
  81. package/package.json +2 -2
  82. package/dist/templates/next-app/src/base/cases/TranslateI18nInterface.ts +0 -25
  83. package/dist/templates/next-app/src/base/cases/UserServiceApi.ts +0 -78
  84. package/dist/templates/next-app/src/base/services/adminApi/AdminApiRequester.ts +0 -25
  85. package/dist/templates/next-app/src/base/services/appApi/AppUserApi.ts +0 -78
  86. package/dist/templates/next-app/src/server/port/UserControllerInerface.ts +0 -8
@@ -0,0 +1,53 @@
1
+ import { logger } from '@/core/globals';
2
+ import { i18nWarnMissingTranslation } from '@config/common';
3
+ import type { PageI18nInterface } from '@config/i18n';
4
+ import type { Formats, useTranslations } from 'next-intl';
5
+
6
+ /**
7
+ * Translate I18n Interface tools class
8
+ *
9
+ * @param i18nInterface - The i18n interface to translate
10
+ * @param t - The translations function
11
+ * @returns The translated i18n interface
12
+ */
13
+ export class TranslateI18nUtil {
14
+ public static translate<T extends PageI18nInterface | Record<string, string>>(
15
+ source: T,
16
+ t: ReturnType<typeof useTranslations>
17
+ ): T {
18
+ return Object.fromEntries(
19
+ Object.entries(source).map(([key, value]) => {
20
+ if (typeof value === 'string') {
21
+ return [key, t(value)];
22
+ }
23
+ return [key, value];
24
+ })
25
+ ) as T;
26
+ }
27
+
28
+ public static overrideTranslateT(
29
+ t: ReturnType<typeof useTranslations>
30
+ ): ReturnType<typeof useTranslations> {
31
+ return function ot(
32
+ key: string,
33
+ values?: Record<string, string | number | Date> | undefined,
34
+ formats?: Formats | undefined
35
+ ) {
36
+ try {
37
+ if (!i18nWarnMissingTranslation) {
38
+ return t(key, values, formats);
39
+ }
40
+
41
+ if (t.has(key)) {
42
+ return t(key, values, formats);
43
+ }
44
+
45
+ logger.warn(`[i18n] Missing translation: ${key}`);
46
+ } catch (e) {
47
+ logger.error(`[i18n] Error translation: ${key}`, String(e));
48
+ return t.raw(key);
49
+ }
50
+ return key;
51
+ } as ReturnType<typeof useTranslations>;
52
+ }
53
+ }
@@ -70,9 +70,6 @@ export class ZodColumnBuilder<
70
70
  ];
71
71
  }
72
72
 
73
- /**
74
- * @override
75
- */
76
73
  public zod2BaseOption(
77
74
  key: string,
78
75
  zod: ZodType
@@ -99,9 +96,6 @@ export class ZodColumnBuilder<
99
96
  };
100
97
  }
101
98
 
102
- /**
103
- * @override
104
- */
105
99
  public getBaseOptions(input: Input): OptionMap<Value, Input> {
106
100
  return Object.entries(input.shape).reduce(
107
101
  (acc, [key, zod]) => {
@@ -129,9 +123,6 @@ export class ZodColumnBuilder<
129
123
  return this;
130
124
  }
131
125
 
132
- /**
133
- * @override
134
- */
135
126
  public render<K extends keyof Input['shape']>(
136
127
  key: K,
137
128
  render: (
@@ -146,7 +137,6 @@ export class ZodColumnBuilder<
146
137
 
147
138
  /**
148
139
  * Translate all i18n keys in options to actual text
149
- * @override
150
140
  * @param t - Translation function from next-intl
151
141
  * @returns this for chaining
152
142
  */
@@ -22,8 +22,5 @@ export abstract class AdminLayoutInterface extends StoreInterface<AdminPageState
22
22
  navItems: (state: AdminPageState) => state.navItems
23
23
  };
24
24
 
25
- /**
26
- * @override
27
- */
28
25
  public abstract toggleSidebar(): void;
29
26
  }
@@ -1,6 +1,6 @@
1
1
  import type { LoginValidatorData } from '@/server/validators/LoginValidator';
2
2
  import type { UserSchema } from '@migrations/schema/UserSchema';
3
- import type { AppApiTransaction } from '../services/appApi/AppApiRequester';
3
+ import type { AppApiTransaction } from '../services/AppApiRequester';
4
4
 
5
5
  export type UserApiLoginTransaction = AppApiTransaction<
6
6
  LoginValidatorData,
@@ -14,30 +14,12 @@ export class I18nServiceState implements StoreStateInterface {
14
14
  constructor(public language: I18nServiceLocale) {}
15
15
  }
16
16
  export abstract class I18nServiceInterface extends StoreInterface<I18nServiceState> {
17
- /**
18
- * @override
19
- */
20
17
  public abstract t(key: string, params?: Record<string, unknown>): string;
21
- /**
22
- * @override
23
- */
24
18
  public abstract changeLanguage(language: I18nServiceLocale): Promise<void>;
25
- /**
26
- * @override
27
- */
28
19
  public abstract changeLoading(loading: boolean): void;
29
- /**
30
- * @override
31
- */
32
20
  public abstract getCurrentLanguage(): Promise<I18nServiceLocale>;
33
- /**
34
- * @override
35
- */
36
21
  public abstract isValidLanguage(
37
22
  language: string
38
23
  ): language is I18nServiceLocale;
39
- /**
40
- * @override
41
- */
42
24
  public abstract getSupportedLanguages(): I18nServiceLocale[];
43
25
  }
@@ -1,5 +1,8 @@
1
1
  import type { UserCredential, UserSchema } from '@migrations/schema/UserSchema';
2
- import type { UserService as CorekitBridgeUserServiceInterface } from '@qlover/corekit-bridge';
2
+ import type {
3
+ UserService as CorekitBridgeUserServiceInterface,
4
+ UserServiceGateway
5
+ } from '@qlover/corekit-bridge';
3
6
 
4
7
  export interface UserServiceInterface extends CorekitBridgeUserServiceInterface<
5
8
  UserSchema,
@@ -13,8 +16,10 @@ export interface UserServiceInterface extends CorekitBridgeUserServiceInterface<
13
16
  * This is a extends method from the corekit-bridge UserServiceInterface.
14
17
  */
15
18
  getToken(): string;
16
-
17
- isUserInfo(value: unknown): value is UserSchema;
18
-
19
- isUserCredential(value: unknown): value is UserCredential;
20
19
  }
20
+
21
+ export interface UserServiceGatewayInterface extends UserServiceGateway<
22
+ UserSchema,
23
+ UserCredential,
24
+ {}
25
+ > {}
@@ -1,4 +1,8 @@
1
- import { LifecycleExecutor, RequestAdapterFetch, RequestExecutor } from '@qlover/fe-corekit';
1
+ import {
2
+ LifecycleExecutor,
3
+ RequestAdapterFetch,
4
+ RequestExecutor
5
+ } from '@qlover/fe-corekit';
2
6
  import { injectable } from 'inversify';
3
7
  import type { RequestEncryptPluginProps } from '@/base/cases/RequestEncryptPlugin';
4
8
  import type { AppApiResult } from '@/base/port/AppApiInterface';
@@ -14,11 +18,9 @@ export interface RequestTransactionInterface<Request, Response> {
14
18
  }
15
19
 
16
20
  export interface AppApiConfig<Request = unknown>
17
- extends RequestAdapterConfig<Request>,
18
- RequestEncryptPluginProps<Request> {}
21
+ extends RequestAdapterConfig<Request>, RequestEncryptPluginProps<Request> {}
19
22
 
20
- export interface AppApiRequesterContext
21
- extends ExecutorContextInterface<AppApiConfig> {}
23
+ export interface AppApiRequesterContext extends ExecutorContextInterface<AppApiConfig> {}
22
24
 
23
25
  /**
24
26
  * UserApiResponse
@@ -37,11 +39,13 @@ export type AppApiResponse<
37
39
  /**
38
40
  * UserApi common transaction
39
41
  */
40
- export interface AppApiTransaction<Request = unknown, Response = unknown>
41
- extends RequestTransactionInterface<
42
- AppApiConfig<Request>,
43
- AppApiResponse<Request, Response>
44
- > {
42
+ export interface AppApiTransaction<
43
+ Request = unknown,
44
+ Response = unknown
45
+ > extends RequestTransactionInterface<
46
+ AppApiConfig<Request>,
47
+ AppApiResponse<Request, Response>
48
+ > {
45
49
  data: AppApiConfig<Request>['data'];
46
50
  }
47
51
 
@@ -53,7 +57,8 @@ export class AppApiRequester extends RequestExecutor<
53
57
  constructor() {
54
58
  super(
55
59
  new RequestAdapterFetch({
56
- baseURL: '/api',
60
+ // TODO: ReqeustPlugin build url 最后需要带上/
61
+ baseURL: '/api/',
57
62
  responseType: 'json'
58
63
  }),
59
64
  new LifecycleExecutor()
@@ -0,0 +1,110 @@
1
+ import { HttpMethods, RequestExecutor } from '@qlover/fe-corekit';
2
+ import { inject, injectable } from 'inversify';
3
+ import type {
4
+ UserApiLoginTransaction,
5
+ UserApiLogoutTransaction,
6
+ UserApiRegisterTransaction
7
+ } from '@/base/port/AppUserApiInterface';
8
+ import { UserCredential, UserSchema } from '@migrations/schema/UserSchema';
9
+ import {
10
+ AppApiConfig,
11
+ AppApiRequester,
12
+ AppApiRequesterContext
13
+ } from './AppApiRequester';
14
+ import { UserServiceGatewayInterface } from '../port/UserServiceInterface';
15
+ import type { LoginParams } from '@qlover/corekit-bridge';
16
+
17
+ /**
18
+ * UserApi
19
+ *
20
+ * @description
21
+ * UserApi is a client for the user API.
22
+ *
23
+ */
24
+ @injectable()
25
+ export class AppUserGateway implements UserServiceGatewayInterface {
26
+ constructor(
27
+ @inject(AppApiRequester)
28
+ protected client: RequestExecutor<AppApiConfig, AppApiRequesterContext>
29
+ ) {}
30
+
31
+ /**
32
+ * @override
33
+ */
34
+ public getUserInfo(
35
+ _params?: unknown,
36
+ _config?: unknown
37
+ ): Promise<UserSchema | null> {
38
+ throw new Error('Method not implemented.');
39
+ }
40
+ /**
41
+ * @override
42
+ */
43
+ public refreshUserInfo(
44
+ _params?: unknown,
45
+ _config?: {} | undefined
46
+ ): Promise<UserSchema | null> {
47
+ throw new Error('Method not implemented.');
48
+ }
49
+
50
+ /**
51
+ * @override
52
+ */
53
+ public async login(
54
+ params: UserApiLoginTransaction['data'] & LoginParams
55
+ ): Promise<UserCredential> {
56
+ const response = await this.client.request<
57
+ UserApiLoginTransaction['response'],
58
+ UserApiLoginTransaction['request']
59
+ >({
60
+ url: '/user/login',
61
+ method: HttpMethods.POST,
62
+ data: params,
63
+ encryptProps: 'password'
64
+ });
65
+
66
+ if (!response.data.success) {
67
+ throw new Error(response.data.message);
68
+ }
69
+
70
+ return response.data.data as UserCredential;
71
+ }
72
+
73
+ /**
74
+ * @override
75
+ */
76
+ public async register(
77
+ params: UserApiRegisterTransaction['data']
78
+ ): Promise<UserSchema> {
79
+ const response = await this.client.request<
80
+ UserApiRegisterTransaction['response'],
81
+ UserApiRegisterTransaction['request']
82
+ >({
83
+ url: '/user/register',
84
+ method: HttpMethods.POST,
85
+ data: params,
86
+ encryptProps: 'password'
87
+ });
88
+
89
+ if (!response.data.success) {
90
+ throw new Error(response.data.message);
91
+ }
92
+
93
+ return response.data.data as UserSchema;
94
+ }
95
+
96
+ /**
97
+ * @override
98
+ */
99
+ public async logout<R = void>(_params?: unknown): Promise<R> {
100
+ await this.client.request<
101
+ UserApiLogoutTransaction['response'],
102
+ UserApiLogoutTransaction['request']
103
+ >({
104
+ url: '/user/logout',
105
+ method: HttpMethods.POST
106
+ });
107
+
108
+ return undefined as R;
109
+ }
110
+ }
@@ -4,8 +4,8 @@ import {
4
4
  I18nServiceState
5
5
  } from '../port/I18nServiceInterface';
6
6
  import type { I18nServiceLocale } from '../port/I18nServiceInterface';
7
+ import type { BootstrapExecutorPlugin } from '@qlover/corekit-bridge';
7
8
  import type { useTranslations } from 'next-intl';
8
- import { BootstrapExecutorPlugin } from '@qlover/corekit-bridge';
9
9
 
10
10
  type TranslationFunction = ReturnType<typeof useTranslations>;
11
11
 
@@ -21,16 +21,10 @@ export class I18nService
21
21
  super(() => new I18nServiceState(i18nConfig.fallbackLng));
22
22
  }
23
23
 
24
- /**
25
- * @override
26
- */
27
24
  public setPathname(pathname: string): void {
28
25
  this.pathname = pathname;
29
26
  }
30
27
 
31
- /**
32
- * @override
33
- */
34
28
  public setTranslator(translator: TranslationFunction): void {
35
29
  this.translator = translator;
36
30
  }
@@ -6,7 +6,7 @@ import {
6
6
  type ResourceInterface,
7
7
  type ResourceQuery
8
8
  } from '@qlover/corekit-bridge';
9
- import type { AppApiResponse } from '@/base/services/appApi/AppApiRequester';
9
+ import type { AppApiResponse } from '@/base/services/AppApiRequester';
10
10
  import type { PaginationInterface } from '@/server/port/PaginationInterface';
11
11
 
12
12
  export class ResourceService<
@@ -90,9 +90,6 @@ export class ResourceService<
90
90
  return this.store.state.listState.result! as PaginationInterface<T>;
91
91
  }
92
92
 
93
- /**
94
- * @override
95
- */
96
93
  public refresh(): Promise<unknown> {
97
94
  return this.search(this.store.state.searchParams);
98
95
  }
@@ -6,9 +6,15 @@ import {
6
6
  type UserCredential,
7
7
  type UserSchema
8
8
  } from '@migrations/schema/UserSchema';
9
- import { UserServiceApi } from '../cases/UserServiceApi';
10
- import type { UserServiceInterface } from '../port/UserServiceInterface';
11
- import type { UserServiceGateway } from '@qlover/corekit-bridge';
9
+ import { AppUserGateway } from './AppUserGateway';
10
+ import type {
11
+ UserServiceGatewayInterface,
12
+ UserServiceInterface
13
+ } from '../port/UserServiceInterface';
14
+ import type {
15
+ StoreInterface,
16
+ UserStateInterface
17
+ } from '@qlover/corekit-bridge';
12
18
 
13
19
  @injectable()
14
20
  export class UserService
@@ -16,38 +22,43 @@ export class UserService
16
22
  implements UserServiceInterface
17
23
  {
18
24
  constructor(
19
- @inject(UserServiceApi)
20
- userApi: UserServiceGateway<UserSchema, UserCredential>
25
+ @inject(AppUserGateway)
26
+ userApi: UserServiceGatewayInterface
21
27
  ) {
22
- super({
23
- gateway: userApi
24
- // next-js ssr 将 credential 存储在 cookie 中无需存储用户信息到本地
25
- // store: {
26
- // storageKey: appConfig.userInfoKey,
27
- // credentialStorageKey: appConfig.userTokenKey,
28
- // persistUserInfo: true,
29
- // }
30
- });
28
+ super(userApi);
29
+ }
30
+
31
+ /**
32
+ * @override
33
+ */
34
+ public override get gateway(): UserServiceGatewayInterface {
35
+ return super.gateway as UserServiceGatewayInterface;
31
36
  }
32
37
 
33
38
  /**
34
39
  * @override
35
40
  */
36
41
  public getToken(): string {
37
- return this.store.getCredential()?.credential_token ?? '';
42
+ return this.getStore().getCredential()?.credential_token ?? '';
43
+ }
44
+
45
+ public getUIStore(): StoreInterface<
46
+ UserStateInterface<UserSchema, UserCredential>
47
+ > {
48
+ return this.getStore().getStore();
38
49
  }
39
50
 
40
51
  /**
41
52
  * @override
42
53
  */
43
- public isUserInfo(value: unknown): value is UserSchema {
54
+ public isUser(value: unknown): value is UserSchema {
44
55
  return userSchema.safeParse(value).success;
45
56
  }
46
57
 
47
58
  /**
48
59
  * @override
49
60
  */
50
- public isUserCredential(value: unknown): value is UserCredential {
61
+ public isCredential(value: unknown): value is UserCredential {
51
62
  return (
52
63
  isObject(value) &&
53
64
  'credential_token' in value &&
@@ -1,15 +1,16 @@
1
+ import { RequestExecutor } from '@qlover/fe-corekit';
1
2
  import { inject, injectable } from 'inversify';
2
3
  import type { PaginationInterface } from '@/server/port/PaginationInterface';
3
4
  import type { LocalesSchema } from '@migrations/schema/LocalesSchema';
4
5
  import type { LocaleType } from '@config/i18n';
6
+
5
7
  import {
6
8
  AppApiRequester,
9
+ AppApiRequesterContext,
7
10
  type AppApiConfig,
8
11
  type AppApiTransaction
9
- } from '../appApi/AppApiRequester';
12
+ } from '../AppApiRequester';
10
13
  import type { ResourceInterface, ResourceQuery } from '@qlover/corekit-bridge';
11
- import { RequestExecutor } from '@qlover/fe-corekit';
12
- import { AdminApiRequesterContext } from './AdminApiRequester';
13
14
 
14
15
  export type AdminLocalesListTransaction = AppApiTransaction<
15
16
  ResourceQuery,
@@ -25,7 +26,7 @@ export type AdminLocalesUpdateTransaction = AppApiTransaction<
25
26
  export class AdminLocalesApi implements ResourceInterface<LocalesSchema> {
26
27
  constructor(
27
28
  @inject(AppApiRequester)
28
- protected client: RequestExecutor<AppApiConfig, AdminApiRequesterContext>
29
+ protected client: RequestExecutor<AppApiConfig, AppApiRequesterContext>
29
30
  ) {}
30
31
 
31
32
  /**
@@ -87,9 +88,6 @@ export class AdminLocalesApi implements ResourceInterface<LocalesSchema> {
87
88
  });
88
89
  }
89
90
 
90
- /**
91
- * @override
92
- */
93
91
  public import(data: {
94
92
  [key in LocaleType]?: File;
95
93
  }): Promise<unknown> {
@@ -1,3 +1,4 @@
1
+ import { ExecutorContextInterface, RequestExecutor } from '@qlover/fe-corekit';
1
2
  import { inject, injectable } from 'inversify';
2
3
  import type { PaginationInterface } from '@/server/port/PaginationInterface';
3
4
  import type { UserSchema } from '@migrations/schema/UserSchema';
@@ -5,10 +6,10 @@ import {
5
6
  AppApiRequester,
6
7
  type AppApiConfig,
7
8
  type AppApiTransaction
8
- } from '../appApi/AppApiRequester';
9
+ } from '../AppApiRequester';
9
10
  import type { ResourceInterface, ResourceQuery } from '@qlover/corekit-bridge';
10
- import { RequestExecutor } from '@qlover/fe-corekit';
11
- import { AdminApiRequesterContext } from './AdminApiRequester';
11
+
12
+ export interface AdminApiRequesterContext extends ExecutorContextInterface<AppApiConfig> {}
12
13
 
13
14
  export type AdminUserListTransaction = AppApiTransaction<
14
15
  ResourceQuery,
@@ -1,11 +1,11 @@
1
- import {
1
+ import { ExecutorError, isRequestAdapterResponse } from '@qlover/fe-corekit';
2
+ import type { AppApiErrorInterface } from '@/base/port/AppApiInterface';
3
+ import type { AppApiConfig } from '../AppApiRequester';
4
+ import type {
2
5
  ExecutorContextInterface,
3
- ExecutorError,
4
- isRequestAdapterResponse,
6
+ HookRuntimes,
5
7
  LifecyclePluginInterface
6
8
  } from '@qlover/fe-corekit';
7
- import type { AppApiErrorInterface } from '@/base/port/AppApiInterface';
8
- import type { AppApiConfig } from './AppApiRequester';
9
9
  import type { LoggerInterface } from '@qlover/logger';
10
10
 
11
11
  export class AppApiPlugin implements LifecyclePluginInterface<
@@ -15,9 +15,6 @@ export class AppApiPlugin implements LifecyclePluginInterface<
15
15
 
16
16
  constructor(protected logger: LoggerInterface) {}
17
17
 
18
- /**
19
- * @override
20
- */
21
18
  public isAppApiErrorInterface(value: unknown): value is AppApiErrorInterface {
22
19
  return (
23
20
  typeof value === 'object' &&
@@ -29,6 +26,19 @@ export class AppApiPlugin implements LifecyclePluginInterface<
29
26
  );
30
27
  }
31
28
 
29
+ /**
30
+ * @override
31
+ * @param ctx
32
+ */
33
+ public onBefore(
34
+ ctx: ExecutorContextInterface<AppApiConfig<unknown>, unknown, HookRuntimes>
35
+ ): void {
36
+ ctx.setParameters({
37
+ ...ctx.parameters,
38
+ // TODO: ReqeustPlugin 在处理路径后会保留baseUrl,然后拼接 url,但是 fetchAdapter 会再次组合两个参数导致重复
39
+ baseURL: ''
40
+ });
41
+ }
32
42
  /**
33
43
  * @override
34
44
  */
@@ -39,7 +49,10 @@ export class AppApiPlugin implements LifecyclePluginInterface<
39
49
  // Important: 当响应数据失败则抛出错误
40
50
  if (isRequestAdapterResponse(response)) {
41
51
  if (this.isAppApiErrorInterface(response.data)) {
42
- throw new ExecutorError(response.data.message || response.data.id, response);
52
+ throw new ExecutorError(
53
+ response.data.message || response.data.id,
54
+ response
55
+ );
43
56
  }
44
57
  }
45
58
 
@@ -77,9 +90,6 @@ export class AppApiPlugin implements LifecyclePluginInterface<
77
90
  }
78
91
  }
79
92
 
80
- /**
81
- * @override
82
- */
83
93
  protected async getResponseJson(response: Response): Promise<unknown> {
84
94
  try {
85
95
  return await response.json();
@@ -88,15 +98,13 @@ export class AppApiPlugin implements LifecyclePluginInterface<
88
98
  }
89
99
  }
90
100
 
91
- /**
92
- * @override
93
- */
94
101
  protected loggerError(config: AppApiConfig, error: unknown): void {
95
102
  this.logger.error(
96
103
  `%c[AppApi ${config.method} ${config.url}]%c - ${new Date().toLocaleString()}`,
97
104
  'color: #f00;',
98
105
  'color: inherit;',
99
- error
106
+ error,
107
+ config
100
108
  );
101
109
  }
102
110
  }
@@ -4,8 +4,8 @@ import { RequestEncryptPlugin } from '@/base/cases/RequestEncryptPlugin';
4
4
  import { StringEncryptor } from '@/base/cases/StringEncryptor';
5
5
  import { I } from '@config/IOCIdentifier';
6
6
  import { AppApiPlugin } from './AppApiPlugin';
7
- import { AppApiRequester } from './AppApiRequester';
8
- import type { AppApiConfig } from './AppApiRequester';
7
+ import { AppApiRequester } from '../AppApiRequester';
8
+ import type { AppApiConfig } from '../AppApiRequester';
9
9
  import type {
10
10
  BootstrapContext,
11
11
  BootstrapExecutorPlugin
@@ -35,9 +35,6 @@ export class AppUserApiBootstrap implements BootstrapExecutorPlugin {
35
35
  appUserApi.use(ioc.get(DialogErrorPlugin));
36
36
  }
37
37
 
38
- /**
39
- * @override
40
- */
41
38
  protected requestDataSerializer(
42
39
  data: unknown,
43
40
  config: AppApiConfig
@@ -1,31 +1,29 @@
1
1
  import 'reflect-metadata';
2
- import {
3
- type ServiceIdentifier,
4
- type IOCContainerInterface,
5
- type IOCFunctionInterface,
2
+ import { LifecycleExecutor } from '@qlover/fe-corekit';
3
+ import type { ServerInterface } from '@/server/port/ServerInterface';
4
+ import { I, type IOCIdentifierMapServer } from '@config/IOCIdentifier';
5
+ import { ServerIOC } from '../serverIoc/ServerIOC';
6
+ import type {
7
+ ServiceIdentifier,
8
+ IOCContainerInterface,
9
+ IOCFunctionInterface,
6
10
  BootstrapPluginOptions
7
11
  } from '@qlover/corekit-bridge';
8
- import {
12
+ import type {
13
+ ExecutorError,
9
14
  ExecutorAsyncTask,
10
15
  ExecutorContextInterface,
11
- LifecycleExecutor,
12
- LifecyclePluginInterface,
13
- type ExecutorError
16
+ LifecyclePluginInterface
14
17
  } from '@qlover/fe-corekit';
15
- import type { ServerInterface } from '@/server/port/ServerInterface';
16
- import { I, type IOCIdentifierMapServer } from '@config/IOCIdentifier';
17
- import { ServerIOC } from '../serverIoc/ServerIOC';
18
18
  import type { LoggerInterface } from '@qlover/logger';
19
19
 
20
20
  export interface BootstrapServerContextOptions extends BootstrapPluginOptions {
21
21
  IOC: IOCFunctionInterface<IOCIdentifierMapServer, IOCContainerInterface>;
22
22
  }
23
23
 
24
- export interface BootstrapServerPlugin
25
- extends LifecyclePluginInterface<BootstrapServerContext> {}
24
+ export interface BootstrapServerPlugin extends LifecyclePluginInterface<BootstrapServerContext> {}
26
25
 
27
- export interface BootstrapServerContext
28
- extends ExecutorContextInterface<BootstrapServerContextOptions> {}
26
+ export interface BootstrapServerContext extends ExecutorContextInterface<BootstrapServerContextOptions> {}
29
27
 
30
28
  export class BootstrapServer implements ServerInterface {
31
29
  protected executor: LifecycleExecutor<
@@ -80,9 +78,6 @@ export class BootstrapServer implements ServerInterface {
80
78
  return this.IOC(identifier);
81
79
  }
82
80
 
83
- /**
84
- * @override
85
- */
86
81
  public use(
87
82
  plugin:
88
83
  | BootstrapServerPlugin
@@ -126,3 +121,5 @@ export class BootstrapServer implements ServerInterface {
126
121
  );
127
122
  }
128
123
  }
124
+
125
+ export const bootstrapServer = new BootstrapServer();