@gadmin2n/schematics 0.0.55
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/collection.json +122 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/lib/application/application.factory.d.ts +3 -0
- package/dist/lib/application/application.factory.js +92 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/.dockerignore +33 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/Dockerfile +14 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/Jenkinsfile +44 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/build.sh +18 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/.types.d.ts +143 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/prisma/sample.prisma +65 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/ui/Game.ts +58 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/ui/Log.ts +56 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/ui/Role.ts +58 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/ui/Source.ts +76 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/ui/Tasklog.ts +76 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/config/ui/_common.ts +16 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/readme.md +49 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/.env +20 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/.eslintrc.js +25 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/.prettierrc +4 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/README.md +71 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/config/ac.config.ts +24 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/config/index.ts +60 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/gadmin-cli.json +17 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/package.json +106 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/prisma/.generator.prisma +32 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/seed/games.ts +71 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/seed/index.ts +27 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/seed/roles.ts +4 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/app.controller.spec.ts +22 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/app.controller.ts +52 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/app.module.ts +75 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/app.service.ts +50 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/lib/auth.guard.ts +108 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/lib/roles.guard.ts +47 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/lib/utils.ts +54 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/lib/woaAuth.ts +82 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/lib/yufuid.ts +160 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/main.ts +119 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/src/modules/index.ts +3 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/test/app.e2e-spec.ts +24 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/test/jest-e2e.json +9 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/tsconfig.build.json +4 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/server/tsconfig.json +21 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/README.MD +48 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/craco.config.js +27 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/package.json +81 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/public/favicon.ico +0 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/public/images/flags/en.svg +1 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/public/images/flags/zh_CN.svg +11 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/public/index.html +53 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/public/locales/en/common.json +128 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/public/locales/zh_CN/common.json +130 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/App.tsx +185 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/auditLogProvider.ts +87 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/authProvider.ts +124 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/BulkActions.tsx +236 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/ListPageHeader.tsx +56 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/RowActions.tsx +292 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/SearchBar.tsx +294 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/VanillaJSONEditor/index.css +10 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/VanillaJSONEditor/index.js +53 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/AgentContext.tsx +201 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/AgentPanel.tsx +497 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/ElementInspector.tsx +282 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/agentAttributes.ts +61 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/index.ts +18 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/inspectorActions.ts +111 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/promptGenerator.ts +75 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/agentPanel/skills.ts +464 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/auditLog/components/eventList/index.tsx +62 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/auditLog/components/index.ts +4 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/auditLog/components/logButton/index.tsx +96 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/auditLog/components/logList/index.tsx +73 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/auditLog/components/modalDiffViewer/index.tsx +104 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/auditLog/index.tsx +2 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/contexts/business/index.tsx +65 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/contexts/color-mode/index.tsx +60 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/index.ts +4 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/layout/header/index.tsx +130 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/layout/index.ts +2 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/layout/sider.tsx +218 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/layout/styles.ts +10 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/components/offLayoutArea/index.tsx +5 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/helpers/form.tsx +419 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/helpers/index.tsx +3 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/helpers/list.tsx +465 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/helpers/login.ts +124 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/helpers/show.tsx +182 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/helpers/utils.ts +76 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/index.ts +7 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/types.ts +138 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/useBatchDelete.ts +191 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/useBatchOperations.ts +152 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/useBatchOperationsCore.ts +193 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/useBatchUpdate.ts +182 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/useListPageState.ts +303 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/hooks/useRowSelection.ts +38 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/i18n.ts +19 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/index.tsx +28 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/meta.json +4 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/react-app-env.d.ts +1 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/reportWebVitals.ts +15 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/setupTests.ts +5 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/src/styles/antd.less +79 -0
- package/dist/lib/application/files/gadmin2-game-angle-demo/web/tsconfig.json +27 -0
- package/dist/lib/application/schema.json +99 -0
- package/dist/lib/class/class.factory.d.ts +3 -0
- package/dist/lib/class/class.factory.js +42 -0
- package/dist/lib/class/files/js/__name__.js +1 -0
- package/dist/lib/class/files/js/__name__.spec.js +7 -0
- package/dist/lib/class/files/ts/__name__.spec.ts +7 -0
- package/dist/lib/class/files/ts/__name__.ts +1 -0
- package/dist/lib/class/schema.json +45 -0
- package/dist/lib/client-app/angular/angular.factory.d.ts +3 -0
- package/dist/lib/client-app/angular/angular.factory.js +98 -0
- package/dist/lib/client-app/angular/files/angular.constants.ts +4 -0
- package/dist/lib/client-app/angular/files/angular.module.ts +41 -0
- package/dist/lib/client-app/angular/files/angular.providers.ts +27 -0
- package/dist/lib/client-app/angular/files/angular.utils.ts +19 -0
- package/dist/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
- package/dist/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
- package/dist/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
- package/dist/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
- package/dist/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
- package/dist/lib/client-app/angular/schema.json +24 -0
- package/dist/lib/configuration/configuration.factory.d.ts +3 -0
- package/dist/lib/configuration/configuration.factory.js +24 -0
- package/dist/lib/configuration/files/js/nest-cli.json +6 -0
- package/dist/lib/configuration/files/ts/nest-cli.json +5 -0
- package/dist/lib/controller/controller.factory.d.ts +3 -0
- package/dist/lib/controller/controller.factory.js +118 -0
- package/dist/lib/controller/files/js/__name__.controller.js +4 -0
- package/dist/lib/controller/files/js/__name__.controller.spec.js +18 -0
- package/dist/lib/controller/files/ts/__name__.controller.spec.ts +18 -0
- package/dist/lib/controller/files/ts/__name__.controller.ts +137 -0
- package/dist/lib/controller/schema.json +51 -0
- package/dist/lib/decorator/decorator.factory.d.ts +3 -0
- package/dist/lib/decorator/decorator.factory.js +33 -0
- package/dist/lib/decorator/files/js/__name__.decorator.js +3 -0
- package/dist/lib/decorator/files/ts/__name__.decorator.ts +3 -0
- package/dist/lib/decorator/schema.json +36 -0
- package/dist/lib/defaults.d.ts +16 -0
- package/dist/lib/defaults.js +19 -0
- package/dist/lib/filter/files/js/__name__.filter.js +6 -0
- package/dist/lib/filter/files/js/__name__.filter.spec.js +7 -0
- package/dist/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
- package/dist/lib/filter/files/ts/__name__.filter.ts +6 -0
- package/dist/lib/filter/filter.factory.d.ts +3 -0
- package/dist/lib/filter/filter.factory.js +34 -0
- package/dist/lib/filter/schema.json +41 -0
- package/dist/lib/gateway/files/js/__name__.gateway.js +9 -0
- package/dist/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
- package/dist/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
- package/dist/lib/gateway/files/ts/__name__.gateway.ts +9 -0
- package/dist/lib/gateway/gateway.factory.d.ts +3 -0
- package/dist/lib/gateway/gateway.factory.js +62 -0
- package/dist/lib/gateway/schema.json +41 -0
- package/dist/lib/guard/files/js/__name__.guard.js +8 -0
- package/dist/lib/guard/files/js/__name__.guard.spec.js +7 -0
- package/dist/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
- package/dist/lib/guard/files/ts/__name__.guard.ts +11 -0
- package/dist/lib/guard/guard.factory.d.ts +3 -0
- package/dist/lib/guard/guard.factory.js +34 -0
- package/dist/lib/guard/schema.json +41 -0
- package/dist/lib/interceptor/files/js/__name__.interceptor.js +8 -0
- package/dist/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
- package/dist/lib/interceptor/files/ts/default/__name__.interceptor.spec.ts +7 -0
- package/dist/lib/interceptor/files/ts/default/__name__.interceptor.ts +9 -0
- package/dist/lib/interceptor/files/ts/generated/__name__.interceptor.spec.ts +7 -0
- package/dist/lib/interceptor/files/ts/generated/__name__.interceptor.ts +13 -0
- package/dist/lib/interceptor/interceptor.factory.d.ts +3 -0
- package/dist/lib/interceptor/interceptor.factory.js +116 -0
- package/dist/lib/interceptor/schema.json +50 -0
- package/dist/lib/interface/files/__name__.interface.ts +1 -0
- package/dist/lib/interface/interface.factory.d.ts +3 -0
- package/dist/lib/interface/interface.factory.js +32 -0
- package/dist/lib/interface/schema.json +32 -0
- package/dist/lib/library/files/js/.babelrc +4 -0
- package/dist/lib/library/files/js/jsconfig.json +9 -0
- package/dist/lib/library/files/js/src/__name__.module.js +8 -0
- package/dist/lib/library/files/js/src/__name__.service.js +4 -0
- package/dist/lib/library/files/js/src/__name__.service.spec.js +18 -0
- package/dist/lib/library/files/js/src/index.js +2 -0
- package/dist/lib/library/files/ts/src/__name__.module.ts +8 -0
- package/dist/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
- package/dist/lib/library/files/ts/src/__name__.service.ts +4 -0
- package/dist/lib/library/files/ts/src/index.ts +2 -0
- package/dist/lib/library/files/ts/tsconfig.lib.json +9 -0
- package/dist/lib/library/library.factory.d.ts +3 -0
- package/dist/lib/library/library.factory.js +190 -0
- package/dist/lib/library/schema.json +37 -0
- package/dist/lib/middleware/files/js/__name__.middleware.js +8 -0
- package/dist/lib/middleware/files/js/__name__.middleware.spec.js +7 -0
- package/dist/lib/middleware/files/ts/__name__.middleware.spec.ts +7 -0
- package/dist/lib/middleware/files/ts/__name__.middleware.ts +8 -0
- package/dist/lib/middleware/middleware.factory.d.ts +3 -0
- package/dist/lib/middleware/middleware.factory.js +34 -0
- package/dist/lib/middleware/schema.json +41 -0
- package/dist/lib/module/files/js/__name__.module.js +4 -0
- package/dist/lib/module/files/ts/__name__.module.ts +4 -0
- package/dist/lib/module/module.factory.d.ts +3 -0
- package/dist/lib/module/module.factory.js +58 -0
- package/dist/lib/module/schema.json +46 -0
- package/dist/lib/pipe/files/js/__name__.pipe.js +8 -0
- package/dist/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
- package/dist/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
- package/dist/lib/pipe/files/ts/__name__.pipe.ts +8 -0
- package/dist/lib/pipe/pipe.factory.d.ts +3 -0
- package/dist/lib/pipe/pipe.factory.js +34 -0
- package/dist/lib/pipe/schema.json +41 -0
- package/dist/lib/prisma-resource/files/ts/__name__.controller.spec.ts +20 -0
- package/dist/lib/prisma-resource/files/ts/__name__.controller.ts +63 -0
- package/dist/lib/prisma-resource/files/ts/__name__.module.ts +9 -0
- package/dist/lib/prisma-resource/files/ts/__name__.service.spec.ts +18 -0
- package/dist/lib/prisma-resource/files/ts/__name__.service.ts +28 -0
- package/dist/lib/prisma-resource/files/ts/dto/create-__name@singular__.dto.ts +1 -0
- package/dist/lib/prisma-resource/files/ts/dto/create-__name@singular__.input.ts +7 -0
- package/dist/lib/prisma-resource/files/ts/dto/update-__name@singular__.dto.ts +6 -0
- package/dist/lib/prisma-resource/files/ts/dto/update-__name@singular__.input.ts +13 -0
- package/dist/lib/prisma-resource/files/ts/entities/__name@singular@ent__.ts +7 -0
- package/dist/lib/prisma-resource/prisma-resource.factory.d.ts +3 -0
- package/dist/lib/prisma-resource/prisma-resource.factory.js +131 -0
- package/dist/lib/prisma-resource/schema.json +91 -0
- package/dist/lib/provider/files/js/__name__.js +4 -0
- package/dist/lib/provider/files/js/__name__.spec.js +18 -0
- package/dist/lib/provider/files/ts/__name__.spec.ts +18 -0
- package/dist/lib/provider/files/ts/__name__.ts +4 -0
- package/dist/lib/provider/provider.factory.d.ts +3 -0
- package/dist/lib/provider/provider.factory.js +67 -0
- package/dist/lib/provider/schema.json +45 -0
- package/dist/lib/resolver/files/js/__name__.resolver.js +4 -0
- package/dist/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
- package/dist/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
- package/dist/lib/resolver/files/ts/__name__.resolver.ts +4 -0
- package/dist/lib/resolver/resolver.factory.d.ts +3 -0
- package/dist/lib/resolver/resolver.factory.js +62 -0
- package/dist/lib/resolver/schema.json +41 -0
- package/dist/lib/resource/files/ts/__name__.controller.spec.ts +20 -0
- package/dist/lib/resource/files/ts/__name__.controller.ts +63 -0
- package/dist/lib/resource/files/ts/__name__.gateway.spec.ts +19 -0
- package/dist/lib/resource/files/ts/__name__.gateway.ts +34 -0
- package/dist/lib/resource/files/ts/__name__.graphql +24 -0
- package/dist/lib/resource/files/ts/__name__.module.ts +9 -0
- package/dist/lib/resource/files/ts/__name__.resolver.spec.ts +19 -0
- package/dist/lib/resource/files/ts/__name__.resolver.ts +60 -0
- package/dist/lib/resource/files/ts/__name__.service.spec.ts +18 -0
- package/dist/lib/resource/files/ts/__name__.service.ts +28 -0
- package/dist/lib/resource/files/ts/dto/create-__name@singular__.dto.ts +1 -0
- package/dist/lib/resource/files/ts/dto/create-__name@singular__.input.ts +7 -0
- package/dist/lib/resource/files/ts/dto/update-__name@singular__.dto.ts +6 -0
- package/dist/lib/resource/files/ts/dto/update-__name@singular__.input.ts +13 -0
- package/dist/lib/resource/files/ts/entities/__name@singular@ent__.ts +7 -0
- package/dist/lib/resource/resource.factory.d.ts +3 -0
- package/dist/lib/resource/resource.factory.js +131 -0
- package/dist/lib/resource/schema.json +90 -0
- package/dist/lib/service/files/js/__name__.service.js +4 -0
- package/dist/lib/service/files/js/__name__.service.spec.js +18 -0
- package/dist/lib/service/files/ts/__name__.service.spec.ts +18 -0
- package/dist/lib/service/files/ts/__name__.service.ts +4 -0
- package/dist/lib/service/schema.json +41 -0
- package/dist/lib/service/service.factory.d.ts +3 -0
- package/dist/lib/service/service.factory.js +63 -0
- package/dist/lib/sub-app/files/js/.babelrc +4 -0
- package/dist/lib/sub-app/files/js/index.js +2 -0
- package/dist/lib/sub-app/files/js/jsconfig.json +10 -0
- package/dist/lib/sub-app/files/js/src/app.controller.js +15 -0
- package/dist/lib/sub-app/files/js/src/app.controller.spec.js +22 -0
- package/dist/lib/sub-app/files/js/src/app.module.js +10 -0
- package/dist/lib/sub-app/files/js/src/app.service.js +8 -0
- package/dist/lib/sub-app/files/js/src/main.js +8 -0
- package/dist/lib/sub-app/files/js/test/app.e2e-spec.js +23 -0
- package/dist/lib/sub-app/files/js/test/jest-e2e.json +5 -0
- package/dist/lib/sub-app/files/ts/src/__name__.controller.spec.ts +22 -0
- package/dist/lib/sub-app/files/ts/src/__name__.controller.ts +12 -0
- package/dist/lib/sub-app/files/ts/src/__name__.module.ts +10 -0
- package/dist/lib/sub-app/files/ts/src/__name__.service.ts +8 -0
- package/dist/lib/sub-app/files/ts/src/main.ts +8 -0
- package/dist/lib/sub-app/files/ts/test/app.e2e-spec.ts +24 -0
- package/dist/lib/sub-app/files/ts/test/jest-e2e.json +9 -0
- package/dist/lib/sub-app/files/ts/tsconfig.app.json +9 -0
- package/dist/lib/sub-app/schema.json +32 -0
- package/dist/lib/sub-app/sub-app.factory.d.ts +3 -0
- package/dist/lib/sub-app/sub-app.factory.js +245 -0
- package/dist/lib/sub-app/workspace/js/.babelrc +4 -0
- package/dist/lib/sub-app/workspace/js/index.js +2 -0
- package/dist/lib/sub-app/workspace/js/jsconfig.json +10 -0
- package/dist/lib/sub-app/workspace/ts/tsconfig.app.json +9 -0
- package/dist/utils/change.d.ts +46 -0
- package/dist/utils/change.js +95 -0
- package/dist/utils/dependencies.utils.d.ts +15 -0
- package/dist/utils/dependencies.utils.js +42 -0
- package/dist/utils/export-from.declarator.d.ts +10 -0
- package/dist/utils/export-from.declarator.js +39 -0
- package/dist/utils/formatting.d.ts +1 -0
- package/dist/utils/formatting.js +12 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/json-file.util.d.ts +15 -0
- package/dist/utils/json-file.util.js +68 -0
- package/dist/utils/metadata.manager.d.ts +13 -0
- package/dist/utils/metadata.manager.js +162 -0
- package/dist/utils/module-import.declarator.d.ts +10 -0
- package/dist/utils/module-import.declarator.js +39 -0
- package/dist/utils/module-metadata.declarator.d.ts +4 -0
- package/dist/utils/module-metadata.declarator.js +12 -0
- package/dist/utils/module.declarator.d.ts +23 -0
- package/dist/utils/module.declarator.js +32 -0
- package/dist/utils/module.finder.d.ts +13 -0
- package/dist/utils/module.finder.js +24 -0
- package/dist/utils/name.parser.d.ts +12 -0
- package/dist/utils/name.parser.js +17 -0
- package/dist/utils/path.solver.d.ts +4 -0
- package/dist/utils/path.solver.js +14 -0
- package/dist/utils/source-root.helpers.d.ts +8 -0
- package/dist/utils/source-root.helpers.js +35 -0
- package/package.json +99 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// This is your Prisma schema file,
|
|
2
|
+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
3
|
+
datasource db {
|
|
4
|
+
provider = "mysql"
|
|
5
|
+
url = env("DATABASE_URL")
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
generator client {
|
|
9
|
+
provider = "prisma-client-js"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
generator nestjs {
|
|
13
|
+
provider = "prisma-nest-generator"
|
|
14
|
+
output = "../src/generated"
|
|
15
|
+
outputToNestJsResourceStructure = "true"
|
|
16
|
+
exportRelationModifierClasses = "true"
|
|
17
|
+
reExport = "false"
|
|
18
|
+
createDtoPrefix = "Create"
|
|
19
|
+
updateDtoPrefix = "Update"
|
|
20
|
+
dtoSuffix = "Dto"
|
|
21
|
+
entityPrefix = ""
|
|
22
|
+
entitySuffix = "Entity"
|
|
23
|
+
fileNamingStyle = "camel"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
generator react {
|
|
27
|
+
provider = "prisma-react-generator"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generator dbml {
|
|
31
|
+
provider = "prisma-dbml-generator"
|
|
32
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{ label: 'HOK', value: 'u10000000066' },
|
|
3
|
+
{ label: 'PUBG', value: 'ufc454d9b1af70b40588e2a6fa4da4a8b' },
|
|
4
|
+
{ label: 'NIKKE', value: 'uef4312b08dde07820374dd57086ea2fb' },
|
|
5
|
+
{ label: 'Fatshark(战锤)', value: 'e72b4feda779c36a6b6d3cb5eb8efe5d1' },
|
|
6
|
+
{ label: '阿凡达-蓝色行动', value: 'u10000000033' },
|
|
7
|
+
{ label: 'SOP 重生边缘', value: 'eaccc6f302cd02c7e0cf7c806497a3395' },
|
|
8
|
+
{ label: 'Vrising', value: 'ec41360495e0a6b2eb0809ded33746044' },
|
|
9
|
+
{ label: 'Bloodhunt', value: 'e00000000001' },
|
|
10
|
+
{ label: 'Conan Exiles', value: 'efc7a5eee1d6ca668931bcebf69198b60' },
|
|
11
|
+
{ label: 'ACM刺客信条', value: 'e22eae55990dfe9ef2932e5a8234d63db' },
|
|
12
|
+
{
|
|
13
|
+
label: '黎明觉醒(生机/Undawn)',
|
|
14
|
+
value: 'u037857a0ad6aaad86a15227be23adcc4',
|
|
15
|
+
},
|
|
16
|
+
{ label: '幻塔', value: 'u6d721eb69ef7de198bb84be26be6d40b' },
|
|
17
|
+
{ label: 'NBA2', value: 'u03e9e2775cf377904ca6583456d9f411' },
|
|
18
|
+
{ label: 'world of Taris', value: 'u10000000073' },
|
|
19
|
+
{ label: 'CNC', value: 'u10000000074' },
|
|
20
|
+
{
|
|
21
|
+
label: 'Party Animals派对动物',
|
|
22
|
+
value: 'ea08cbff9a96b95174d530e2eb67c5974',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'Super Buckyball Tournament超级巴基球',
|
|
26
|
+
value: 'edd8d6e6890b8dbb27c5c88a082d0143b',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'Blackmyth: Wukong黑神话:悟空',
|
|
30
|
+
value: 'e3798a6c4b1afee6ac5f161202a27a7ae',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'Amazing Cultivation Simulator了不起的修仙模拟器',
|
|
34
|
+
value: 'e49e633f2e87e606376af989abab855a4',
|
|
35
|
+
},
|
|
36
|
+
{ label: 'DFM', value: 'DFM' },
|
|
37
|
+
{ label: 'Apex', value: 'u10000000015' },
|
|
38
|
+
{ label: '龙之谷2', value: 'u9d2a3dcc71529b3e0cd5f486d4cd9adb' },
|
|
39
|
+
{ label: '代号GST', value: 'u10000000075' },
|
|
40
|
+
{ label: '小森生活', value: 'ubc78e405a8e320c58a8247299252c522' },
|
|
41
|
+
{ label: 'CODM', value: 'uef76e8182c79db6aafefdfbdd04b7d99' },
|
|
42
|
+
{ label: 'UAMO', value: 'u10000000022' },
|
|
43
|
+
{ label: 'Nightingale', value: 'e11000000297' },
|
|
44
|
+
{ label: 'Brawl Stars', value: 'u84eb1af3a729e5d540b6b78073938574' },
|
|
45
|
+
{ label: 'Transformers Reactivate', value: 'e11000000300' },
|
|
46
|
+
{ label: 'Project Astrid', value: 'e11000000301' },
|
|
47
|
+
{ label: 'Path of Exile', value: 'e91eeea272398097f28c93d0a49f58379' },
|
|
48
|
+
{ label: 'GTFO', value: 'e0e9148a8f7c2e98a5b7d538a75afc932' },
|
|
49
|
+
{ label: 'Warframe', value: 'e11000000282' },
|
|
50
|
+
{ label: 'Xdefiant', value: 'e11000000302' },
|
|
51
|
+
{ label: 'Project EVO', value: 'u10000000079' },
|
|
52
|
+
{ label: 'Derby', value: 'u610b8f6f9103f9431dac99aa5bd45953' },
|
|
53
|
+
{ label: 'Jade', value: 'u10000000071' },
|
|
54
|
+
{ label: 'PAX DEI', value: 'ece5b843df224627f4cc626d9e1f84db5' },
|
|
55
|
+
{ label: 'Perfect New World', value: 'e42a5670bf7a585bce3ac55ad2c384284' },
|
|
56
|
+
{ label: 'Lost Ark', value: 'e7052d6286075a212db99f5ecb452a340' },
|
|
57
|
+
{ label: 'Life After', value: 'u6869b6d91db0225ff10cdf25178b5da6' },
|
|
58
|
+
{
|
|
59
|
+
label: 'ミスティックアビス:遺失海域',
|
|
60
|
+
value: 'u48be1ec5b04c723a894928133d31059c',
|
|
61
|
+
},
|
|
62
|
+
{ label: 'Once Human', value: 'u909c7ab2e46afc2bc64442c51c62126d' },
|
|
63
|
+
{ label: 'Marathon', value: 'e11000000306' },
|
|
64
|
+
{ label: 'Eggy Party', value: 'u1e7b2b31e2fc1897e6093cd1ee2925b4' },
|
|
65
|
+
{ label: 'AOV', value: 'u539c87d525e9cf649cea9bc6319d4b8f' },
|
|
66
|
+
{ label: 'MLBB', value: 'u1426b49d8626e915264442d821e41a4e' },
|
|
67
|
+
{ label: 'Wild Rift', value: 'u354f6a7c0b0b7af46839c9b4beeefe15' },
|
|
68
|
+
{ label: 'Free Fire', value: 'u589791f804845507e85fa880c6d88d41' },
|
|
69
|
+
{ label: 'AIGC', value: 'u10000000080' },
|
|
70
|
+
{ label: 'Garena Undawn', value: 'u337f01e5662eb90de6e6aafb28f0a4be' },
|
|
71
|
+
];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import { PrismaClient } from '@prisma/client';
|
|
3
|
+
import games from './games';
|
|
4
|
+
import roles from './roles';
|
|
5
|
+
|
|
6
|
+
const prisma = new PrismaClient();
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await prisma.game.createMany({
|
|
10
|
+
data: games.map((game) => ({
|
|
11
|
+
unified_editionid: game.value,
|
|
12
|
+
name: game.label,
|
|
13
|
+
creator: 'clzhu',
|
|
14
|
+
})),
|
|
15
|
+
skipDuplicates: true,
|
|
16
|
+
});
|
|
17
|
+
await prisma.role.createMany({ data: roles });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
main()
|
|
21
|
+
.catch((e) => {
|
|
22
|
+
console.log(e);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
})
|
|
25
|
+
.finally(async () => {
|
|
26
|
+
await prisma.$disconnect();
|
|
27
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { AppController } from './app.controller';
|
|
3
|
+
import { AppService } from './app.service';
|
|
4
|
+
|
|
5
|
+
describe('AppController', () => {
|
|
6
|
+
let appController: AppController;
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
const app: TestingModule = await Test.createTestingModule({
|
|
10
|
+
controllers: [AppController],
|
|
11
|
+
providers: [AppService],
|
|
12
|
+
}).compile();
|
|
13
|
+
|
|
14
|
+
appController = app.get<AppController>(AppController);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('root', () => {
|
|
18
|
+
it('should return "Hello World!"', () => {
|
|
19
|
+
expect(appController.getHello()).toBe('Hello World!');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { UserType } from '@gadmin2/nest-common';
|
|
2
|
+
import { Controller, Get, Req, Res } from '@nestjs/common';
|
|
3
|
+
import { ApiOkResponse, ApiProperty } from '@nestjs/swagger';
|
|
4
|
+
import { Request } from 'express';
|
|
5
|
+
import { AppService } from './app.service';
|
|
6
|
+
import { AllowUnauthorizedRequest } from './lib/auth.guard';
|
|
7
|
+
|
|
8
|
+
class UserInfo {
|
|
9
|
+
@ApiProperty()
|
|
10
|
+
userid: string;
|
|
11
|
+
|
|
12
|
+
@ApiProperty()
|
|
13
|
+
username: string;
|
|
14
|
+
}
|
|
15
|
+
@Controller()
|
|
16
|
+
export class AppController {
|
|
17
|
+
constructor(private readonly appService: AppService) {}
|
|
18
|
+
|
|
19
|
+
@Get()
|
|
20
|
+
index(@Res() res) {
|
|
21
|
+
res.status(302).redirect('/dashboard');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Get('/userinfo')
|
|
25
|
+
@ApiOkResponse({ type: UserInfo })
|
|
26
|
+
userInfo(@Req() request: Request & { user: UserType }) {
|
|
27
|
+
return request?.user || { userid: '', username: '' };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Get('/hello')
|
|
31
|
+
hello(): string {
|
|
32
|
+
return this.appService.getHello();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Get('/login-callback')
|
|
36
|
+
@AllowUnauthorizedRequest()
|
|
37
|
+
loginCallback(@Req() request: Request, @Res() res) {
|
|
38
|
+
return this.appService.loginCallback(request, res);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Get('login')
|
|
42
|
+
@AllowUnauthorizedRequest()
|
|
43
|
+
login(@Req() request: Request, @Res() res) {
|
|
44
|
+
return this.appService.login(request, res);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Get('logout')
|
|
48
|
+
@AllowUnauthorizedRequest()
|
|
49
|
+
logout(@Req() request: Request, @Res() res) {
|
|
50
|
+
return this.appService.logout(request, res);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
3
|
+
// import { ScheduleModule } from '@nestjs/schedule';
|
|
4
|
+
import { AccessControlModule } from 'nest-access-control';
|
|
5
|
+
import {
|
|
6
|
+
// utilities as nestWinstonModuleUtilities,
|
|
7
|
+
WinstonModule,
|
|
8
|
+
} from 'nest-winston';
|
|
9
|
+
import { PrismaModule } from 'nestjs-prisma';
|
|
10
|
+
import * as winston from 'winston';
|
|
11
|
+
import config from '../config';
|
|
12
|
+
import { roles as appRoles } from '../config/ac.config';
|
|
13
|
+
import { AppController } from './app.controller';
|
|
14
|
+
import { AppService } from './app.service';
|
|
15
|
+
import modules from './modules';
|
|
16
|
+
|
|
17
|
+
import { ServeStaticModule } from '@nestjs/serve-static';
|
|
18
|
+
import { join } from 'path';
|
|
19
|
+
|
|
20
|
+
@Module({
|
|
21
|
+
imports: [
|
|
22
|
+
// ScheduleModule.forRoot(),
|
|
23
|
+
|
|
24
|
+
ServeStaticModule.forRoot({
|
|
25
|
+
rootPath: join(__dirname, '..', 'www'),
|
|
26
|
+
exclude: ['/api/(.*)'],
|
|
27
|
+
}),
|
|
28
|
+
|
|
29
|
+
ConfigModule.forRoot({ isGlobal: true, load: [config] }),
|
|
30
|
+
|
|
31
|
+
AccessControlModule.forRoles(appRoles),
|
|
32
|
+
|
|
33
|
+
WinstonModule.forRootAsync({
|
|
34
|
+
useFactory: (configService: ConfigService) => {
|
|
35
|
+
const loggerConfig = configService.get('logger');
|
|
36
|
+
return {
|
|
37
|
+
level: loggerConfig.level,
|
|
38
|
+
transports: [
|
|
39
|
+
new winston.transports.Console({
|
|
40
|
+
format: winston.format.combine(
|
|
41
|
+
// nestWinstonModuleUtilities.format.nestLike(),
|
|
42
|
+
winston.format.splat(),
|
|
43
|
+
winston.format.timestamp(),
|
|
44
|
+
// winston.format.ms(),
|
|
45
|
+
winston.format.json(),
|
|
46
|
+
// nestWinstonModuleUtilities.format.nestLike('MyApp', { prettyPrint: true }),
|
|
47
|
+
),
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
inject: [ConfigService],
|
|
53
|
+
}),
|
|
54
|
+
|
|
55
|
+
PrismaModule.forRootAsync({
|
|
56
|
+
isGlobal: true,
|
|
57
|
+
useFactory: async (configService: ConfigService) => {
|
|
58
|
+
const prismaConfig = configService.get('prisma');
|
|
59
|
+
return {
|
|
60
|
+
prismaOptions: {
|
|
61
|
+
log: prismaConfig.log,
|
|
62
|
+
},
|
|
63
|
+
explicitConnect: prismaConfig.explicit,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
inject: [ConfigService],
|
|
67
|
+
}),
|
|
68
|
+
|
|
69
|
+
...modules,
|
|
70
|
+
],
|
|
71
|
+
|
|
72
|
+
controllers: [AppController],
|
|
73
|
+
providers: [AppService],
|
|
74
|
+
})
|
|
75
|
+
export class AppModule {}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import YuFuId, { GAdminTokenName } from './lib/yufuid';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class AppService {
|
|
6
|
+
getHello(): string {
|
|
7
|
+
return 'Hello World!';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async loginCallback(req, res) {
|
|
11
|
+
const { code, state } = req.query;
|
|
12
|
+
|
|
13
|
+
const tokenInfo = await YuFuId.getToken(code);
|
|
14
|
+
const userInfo = await YuFuId.getUserInfo(tokenInfo.access_token);
|
|
15
|
+
|
|
16
|
+
const expiresIn = 7 * 24 * 3600;
|
|
17
|
+
const { user_id, sub, name, email } = userInfo;
|
|
18
|
+
const payload = { user_id, sub, name, email };
|
|
19
|
+
const token = await YuFuId.sign(payload, expiresIn);
|
|
20
|
+
|
|
21
|
+
// append token param for local development
|
|
22
|
+
const url = new URL(state);
|
|
23
|
+
if (url.port != '') {
|
|
24
|
+
url.searchParams.set(GAdminTokenName, token);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
res.cookie(GAdminTokenName, token, {
|
|
28
|
+
maxAge: expiresIn * 1000,
|
|
29
|
+
httpOnly: false,
|
|
30
|
+
});
|
|
31
|
+
res.status(302).redirect(url.toString());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
login(req, res) {
|
|
35
|
+
const { redirect_url, ui_locales = 'zh-CN' } = req.query;
|
|
36
|
+
|
|
37
|
+
// TODO: verify redirect_url domain
|
|
38
|
+
|
|
39
|
+
const authorizeUrl = YuFuId.authorize(redirect_url, ui_locales);
|
|
40
|
+
res.status(302).redirect(authorizeUrl);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
logout(req, res) {
|
|
44
|
+
const { redirect_url } = req.query;
|
|
45
|
+
|
|
46
|
+
const logoutUrl = YuFuId.logout(redirect_url);
|
|
47
|
+
res.cookie(GAdminTokenName);
|
|
48
|
+
res.status(302).redirect(logoutUrl);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// https://iwiki.woa.com/pages/viewpage.action?pageId=4007728669
|
|
2
|
+
// node version >= v12.22
|
|
3
|
+
// npm i jose@4.14.4
|
|
4
|
+
import { UserType } from '@gadmin2/nest-common';
|
|
5
|
+
import {
|
|
6
|
+
CanActivate,
|
|
7
|
+
ExecutionContext,
|
|
8
|
+
Injectable,
|
|
9
|
+
SetMetadata,
|
|
10
|
+
UnauthorizedException,
|
|
11
|
+
} from '@nestjs/common';
|
|
12
|
+
import { Reflector } from '@nestjs/core';
|
|
13
|
+
import { ApiSecurity } from '@nestjs/swagger';
|
|
14
|
+
import { DECORATORS_PREFIX } from '@nestjs/swagger/dist/constants';
|
|
15
|
+
import { getIdentity as getWoaIdentity } from './woaAuth';
|
|
16
|
+
import YuFuId, { GAdminTokenName } from './yufuid';
|
|
17
|
+
|
|
18
|
+
const API_SECURITY = `${DECORATORS_PREFIX}/apiSecurity`;
|
|
19
|
+
export function ApiKeyAuth(name = 'X-API-KEY') {
|
|
20
|
+
return ApiSecurity(name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const AllowUnauthorizedRequest = () =>
|
|
24
|
+
SetMetadata('allowUnauthorizedRequest', true);
|
|
25
|
+
|
|
26
|
+
export const AllowApiKeyRequest = () => SetMetadata('allowApiKeyRequest', true);
|
|
27
|
+
|
|
28
|
+
async function getIdentity(headers, cookies, key): Promise<UserType> {
|
|
29
|
+
// 先验证woa登录态
|
|
30
|
+
try {
|
|
31
|
+
const { staffid, staffname } = await getWoaIdentity(headers, key);
|
|
32
|
+
if (staffid) {
|
|
33
|
+
return { userid: staffid, username: staffname };
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.warn('woa auth failed, try yufu auth...');
|
|
37
|
+
}
|
|
38
|
+
// 再验证玉符登录态
|
|
39
|
+
const token = headers[GAdminTokenName] || cookies[GAdminTokenName];
|
|
40
|
+
const userInfo = await YuFuId.verify(token);
|
|
41
|
+
console.log('yufu auth success', userInfo);
|
|
42
|
+
return { userid: userInfo.sub, username: userInfo.sub };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// apikey genertor https://codepen.io/corenominal/pen/rxOmMJ
|
|
46
|
+
const API_KEYS = [
|
|
47
|
+
{
|
|
48
|
+
userid: 'steam_session',
|
|
49
|
+
username: 'steam_session',
|
|
50
|
+
apiKey: '9c5fc474-9e95-480b-b380-5e15f77b5f9f',
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
async function getApikeyIdentity(req): Promise<UserType> {
|
|
54
|
+
const apiKey = req.headers['x-api-key'] ?? req.query.api_key;
|
|
55
|
+
if (apiKey) {
|
|
56
|
+
for (const item of API_KEYS) {
|
|
57
|
+
if (item.apiKey === apiKey) {
|
|
58
|
+
console.log('apikey auth success:', item.userid);
|
|
59
|
+
return { userid: item.userid, username: item.username };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw new UnauthorizedException(`error apikey: ${apiKey}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Injectable()
|
|
67
|
+
export default class AuthGuard implements CanActivate {
|
|
68
|
+
constructor(private readonly token: string, private reflector: Reflector) {}
|
|
69
|
+
|
|
70
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> {
|
|
71
|
+
const request = context.switchToHttp().getRequest();
|
|
72
|
+
const allowUnauthorizedRequest = this.reflector.get<boolean>(
|
|
73
|
+
'allowUnauthorizedRequest',
|
|
74
|
+
context.getHandler(),
|
|
75
|
+
);
|
|
76
|
+
if (allowUnauthorizedRequest) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const allowApiKeyRequest = this.reflector.get<boolean>(
|
|
81
|
+
API_SECURITY,
|
|
82
|
+
context.getHandler(),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
allowApiKeyRequest
|
|
87
|
+
? getApikeyIdentity(request)
|
|
88
|
+
: Promise.reject("don't allow api key request.")
|
|
89
|
+
)
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
console.warn(error, 'try woa auth...');
|
|
92
|
+
|
|
93
|
+
return getIdentity(
|
|
94
|
+
request.headers,
|
|
95
|
+
request.cookies,
|
|
96
|
+
Buffer.from(this.token),
|
|
97
|
+
);
|
|
98
|
+
})
|
|
99
|
+
.then((userInfo) => {
|
|
100
|
+
request.user = userInfo;
|
|
101
|
+
return true;
|
|
102
|
+
})
|
|
103
|
+
.catch((error) => {
|
|
104
|
+
console.error(error);
|
|
105
|
+
throw new UnauthorizedException(error);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { UserType } from '@gadmin2/nest-common';
|
|
2
|
+
import {
|
|
3
|
+
CanActivate,
|
|
4
|
+
ExecutionContext,
|
|
5
|
+
ForbiddenException,
|
|
6
|
+
Injectable,
|
|
7
|
+
} from '@nestjs/common';
|
|
8
|
+
import { Reflector } from '@nestjs/core';
|
|
9
|
+
type RolesGetter = (
|
|
10
|
+
user: UserType,
|
|
11
|
+
) => Promise<{ business?: (string | number)[]; roles: string[] }>;
|
|
12
|
+
|
|
13
|
+
@Injectable()
|
|
14
|
+
export default class RolesGuard implements CanActivate {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly getter: RolesGetter,
|
|
17
|
+
private reflector: Reflector,
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> {
|
|
21
|
+
const req = context.switchToHttp().getRequest();
|
|
22
|
+
|
|
23
|
+
const allowUnauthorizedRequest = this.reflector.get<boolean>(
|
|
24
|
+
'allowUnauthorizedRequest',
|
|
25
|
+
context.getHandler(),
|
|
26
|
+
);
|
|
27
|
+
if (allowUnauthorizedRequest) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!req.user) {
|
|
32
|
+
throw new ForbiddenException();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return this.getter(req.user)
|
|
36
|
+
.then((configPerms) => {
|
|
37
|
+
if (configPerms.roles.length === 0) {
|
|
38
|
+
throw new ForbiddenException();
|
|
39
|
+
}
|
|
40
|
+
req.user.configPerms = configPerms;
|
|
41
|
+
return true;
|
|
42
|
+
})
|
|
43
|
+
.catch((_) => {
|
|
44
|
+
throw new ForbiddenException();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const CryptoJS = require('crypto-js');
|
|
3
|
+
|
|
4
|
+
export function md5(text: string) {
|
|
5
|
+
return crypto.createHash('md5').update(text).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// https://segmentfault.com/a/1190000039192480
|
|
9
|
+
/**
|
|
10
|
+
* AES-256-ECB对称加密
|
|
11
|
+
* @param text {string} 要加密的明文
|
|
12
|
+
* @param secretKey {string} 密钥,43位随机大小写与数字
|
|
13
|
+
* @returns {string} 加密后的密文,Base64格式
|
|
14
|
+
*/
|
|
15
|
+
export function AES_ECB_ENCRYPT(text: string, secretKey: string): string {
|
|
16
|
+
const keyHex = CryptoJS.enc.Base64.parse(secretKey);
|
|
17
|
+
const messageHex = CryptoJS.enc.Utf8.parse(text);
|
|
18
|
+
const encrypted = CryptoJS.AES.encrypt(messageHex, keyHex, {
|
|
19
|
+
mode: CryptoJS.mode.ECB,
|
|
20
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
21
|
+
});
|
|
22
|
+
return encrypted.toString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* AES-256-ECB对称解密
|
|
27
|
+
* @param textBase64 {string} 要解密的密文,Base64格式
|
|
28
|
+
* @param secretKey {string} 密钥,43位随机大小写与数字
|
|
29
|
+
* @returns {string} 解密后的明文
|
|
30
|
+
*/
|
|
31
|
+
export function AES_ECB_DECRYPT(textBase64: string, secretKey: string): string {
|
|
32
|
+
const keyHex = CryptoJS.enc.Base64.parse(secretKey);
|
|
33
|
+
const decrypt = CryptoJS.AES.decrypt(textBase64, keyHex, {
|
|
34
|
+
mode: CryptoJS.mode.ECB,
|
|
35
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
36
|
+
});
|
|
37
|
+
return CryptoJS.enc.Utf8.stringify(decrypt);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function addFieldIfExist(
|
|
41
|
+
name: string,
|
|
42
|
+
value: any,
|
|
43
|
+
obj: any,
|
|
44
|
+
anthor: any = undefined,
|
|
45
|
+
) {
|
|
46
|
+
if (value !== undefined) {
|
|
47
|
+
if (anthor !== undefined) {
|
|
48
|
+
obj[name] = anthor;
|
|
49
|
+
} else {
|
|
50
|
+
obj[name] = value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// https://iwiki.woa.com/pages/viewpage.action?pageId=4007728669
|
|
2
|
+
// node version >= v12.22
|
|
3
|
+
// npm i jose@4.14.4
|
|
4
|
+
import { UserType } from '@gadmin2/nest-common';
|
|
5
|
+
import {
|
|
6
|
+
CanActivate,
|
|
7
|
+
ExecutionContext,
|
|
8
|
+
Injectable,
|
|
9
|
+
UnauthorizedException,
|
|
10
|
+
} from '@nestjs/common';
|
|
11
|
+
const crypto = require('crypto'); //改成import,运行时会报错
|
|
12
|
+
const jose = require('jose'); //改成import,运行时会报错
|
|
13
|
+
|
|
14
|
+
async function decodeAuthorizationHeader(authorizationHeader, key) {
|
|
15
|
+
const dec = await jose.compactDecrypt(authorizationHeader, key);
|
|
16
|
+
const payload = JSON.parse(dec.plaintext as any);
|
|
17
|
+
|
|
18
|
+
const exp = new Date(payload.Expiration);
|
|
19
|
+
// 检验 token 是否已经过期,增加5分钟缓冲,避免服务器时间差异
|
|
20
|
+
if (new Date(new Date().getTime() - 3 * 60 * 1000) > exp) {
|
|
21
|
+
// demo 为了正常运行,此处异常注释了,实际环境需要开启验证
|
|
22
|
+
throw new Error('expired');
|
|
23
|
+
}
|
|
24
|
+
return payload;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function checkSignature(key, timestampSeconds, signature, extHeaders) {
|
|
28
|
+
if (!timestampSeconds || isNaN(timestampSeconds)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (
|
|
32
|
+
!(Math.abs(parseInt(timestampSeconds, 10) * 1000 - Date.now()) <= 180000)
|
|
33
|
+
) {
|
|
34
|
+
// demo 为了正常运行,此处异常注释了,实际环境需要开启验证
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const hash = crypto.createHash('sha256');
|
|
39
|
+
hash.update(timestampSeconds + key + extHeaders.join(',') + timestampSeconds);
|
|
40
|
+
return signature.toLowerCase() === hash.digest('hex').toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function getIdentity(headers, key) {
|
|
44
|
+
const { staffid = '', staffname = '' } = headers;
|
|
45
|
+
const extHeaders = [
|
|
46
|
+
headers['x-rio-seq'],
|
|
47
|
+
staffid,
|
|
48
|
+
staffname,
|
|
49
|
+
headers['x-ext-data'] || '',
|
|
50
|
+
];
|
|
51
|
+
if (!checkSignature(key, headers.timestamp, headers.signature, extHeaders)) {
|
|
52
|
+
throw new Error('check smartgate signature failed');
|
|
53
|
+
}
|
|
54
|
+
const taiIdentity = headers['x-tai-identity'];
|
|
55
|
+
if (taiIdentity) {
|
|
56
|
+
const payload = await decodeAuthorizationHeader(taiIdentity, key);
|
|
57
|
+
return { staffid: payload.StaffId, staffname: payload.LoginName };
|
|
58
|
+
}
|
|
59
|
+
return { staffid: parseInt(staffid, 10) || 0, staffname };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Injectable()
|
|
63
|
+
export class WoaAuthGuard implements CanActivate {
|
|
64
|
+
constructor(private readonly token: string) {}
|
|
65
|
+
|
|
66
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> {
|
|
67
|
+
const request = context.switchToHttp().getRequest();
|
|
68
|
+
return getIdentity(request.headers, Buffer.from(this.token))
|
|
69
|
+
.then((userInfo) => {
|
|
70
|
+
const user: UserType = {
|
|
71
|
+
userid: userInfo.staffid,
|
|
72
|
+
username: userInfo.staffname,
|
|
73
|
+
};
|
|
74
|
+
request.user = user;
|
|
75
|
+
return true;
|
|
76
|
+
})
|
|
77
|
+
.catch((error) => {
|
|
78
|
+
console.log('UnauthorizedException');
|
|
79
|
+
throw new UnauthorizedException(error);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|