@simitgroup/simpleapp-generator 2.0.2-u-alpha → 2.0.2-w-alpha

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 (47) hide show
  1. package/ReleaseNote.md +14 -0
  2. package/dist/buildinschemas/autoincreament.d.ts +3 -0
  3. package/dist/buildinschemas/autoincreament.d.ts.map +1 -0
  4. package/dist/buildinschemas/autoincreament.js +39 -0
  5. package/dist/buildinschemas/autoincreament.js.map +1 -0
  6. package/dist/buildinschemas/docnoformat.d.ts +3 -0
  7. package/dist/buildinschemas/docnoformat.d.ts.map +1 -0
  8. package/dist/buildinschemas/docnoformat.js +58 -0
  9. package/dist/buildinschemas/docnoformat.js.map +1 -0
  10. package/dist/buildinschemas/documentevent.d.ts +3 -0
  11. package/dist/buildinschemas/documentevent.d.ts.map +1 -0
  12. package/dist/buildinschemas/documentevent.js +48 -0
  13. package/dist/buildinschemas/documentevent.js.map +1 -0
  14. package/dist/buildinschemas/webhooklog.d.ts +3 -0
  15. package/dist/buildinschemas/webhooklog.d.ts.map +1 -0
  16. package/dist/buildinschemas/webhooklog.js +79 -0
  17. package/dist/buildinschemas/webhooklog.js.map +1 -0
  18. package/dist/framework.d.ts.map +1 -1
  19. package/dist/framework.js +8 -18
  20. package/dist/framework.js.map +1 -1
  21. package/dist/generate.d.ts.map +1 -1
  22. package/dist/generate.js +8 -18
  23. package/dist/generate.js.map +1 -1
  24. package/dist/index.js +7 -17
  25. package/dist/index.js.map +1 -1
  26. package/dist/libs.d.ts.map +1 -1
  27. package/dist/processors/bpmnbuilder.d.ts.map +1 -1
  28. package/dist/processors/bpmnbuilder.js +7 -17
  29. package/dist/processors/bpmnbuilder.js.map +1 -1
  30. package/dist/processors/jrxmlbuilder.d.ts.map +1 -1
  31. package/dist/processors/jrxmlbuilder.js +7 -17
  32. package/dist/processors/jrxmlbuilder.js.map +1 -1
  33. package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
  34. package/dist/processors/jsonschemabuilder.js.map +1 -1
  35. package/package.json +1 -1
  36. package/templates/nest/src/simple-app/_core/features/mini-app/mini-app-manager/mini-app-manager.controller.ts.eta +2 -3
  37. package/templates/nest/src/simple-app/_core/features/profile/profile.controller.ts.eta +6 -6
  38. package/templates/nest/src/simple-app/_core/features/profile/profile.schema.ts.eta +36 -4
  39. package/templates/nest/src/simple-app/_core/features/user-context/user-context.type.ts.eta +43 -13
  40. package/templates/nest/src/simple-app/_core/features/user-context/user.context.ts.eta +57 -37
  41. package/templates/nest/src/simple-app/_core/framework/schemas/simple-app.schema.ts.eta +4 -3
  42. package/templates/nest/src/simple-app/_core/utils/dayjs.ts.eta +14 -9
  43. package/templates/nuxt/app.vue.eta +46 -47
  44. package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +102 -90
  45. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +70 -52
  46. package/templates/nuxt/server/api/profile/[...].ts.eta +153 -160
  47. package/templates/nuxt/server/api/profile/index.ts.eta +11 -12
@@ -4,172 +4,165 @@
4
4
  * last change 2024-02-23
5
5
  * Author: Ks Tan
6
6
  */
7
-
8
- import axios from 'axios';
9
- import { getServerSession } from '#auth'
10
- import type { Session } from 'next-auth';
11
- import { pathJoin } from '~/server/utils/path';
12
-
13
- export default defineEventHandler(async (event:any) => {
14
- type additionalprops = {accessToken?:string}
15
- let session:any=null
16
- // console.log("profile api-------------------------")
17
-
18
- try {
19
- session = await getServerSession(event)
20
-
21
- } catch (error) {
22
- return sendRedirect(event, '/login', 401)
23
- }
24
- if(!session) {
25
- throw createError({ statusText: 'Unauthorized', status: 302 })
26
- }
27
- return new Promise<any>(async (resolve, reject) => {
28
-
29
- const seperateSymbol = '.';
30
- const documentLink = event.context.params?._ ?? ''
31
- const accessToken = session?.accessToken;
32
- let forwardData: any = {};
33
7
 
34
- const req = event.node.req;
8
+ import { getServerSession } from "#auth";
9
+ import axios from "axios";
10
+ import fs from "node:fs";
11
+ import { pathJoin } from "~/server/utils/path";
35
12
 
36
- if(req.method == 'POST' || req.method == 'PUT' || req.method == 'PATCH') {
13
+ export default defineEventHandler(async (event: any) => {
14
+ type additionalprops = { accessToken?: string };
15
+ let session: any = null;
16
+ // console.log("profile api-------------------------")
37
17
 
38
- forwardData = await readBody(event);
39
- } else {
40
- forwardData = getQuery(event);
41
- }
18
+ try {
19
+ session = await getServerSession(event);
20
+ } catch (error) {
21
+ return sendRedirect(event, "/login", 302);
22
+ }
23
+ if (!session) {
24
+ return sendRedirect(event, "/login", 302);
25
+ }
26
+ return new Promise<any>(async (resolve, reject) => {
27
+ const seperateSymbol = ".";
28
+ const documentLink = event.context.params?._ ?? "";
29
+ const accessToken = session?.accessToken;
30
+ let forwardData: any = {};
42
31
 
43
- // if(typeof forwardData === "object" && "_branch" in forwardData) {
44
- // xOrg = xOrg + forwardData._branch;
45
- // delete forwardData._branch;
46
- // }
47
-
48
- const frontEndRes = event.node.res;
49
-
50
- const url = process.env.SIMPLEAPP_BACKEND_URL + `/profile/${documentLink}`;
51
- // console.warn('backend server-----',req.method,url,forwardData)
52
-
53
-
54
- const axiosConfig: any = {
55
- method: req.method,
56
- url: url,
57
- headers: {
58
- Authorization: `Bearer ${accessToken}`,
59
- },
60
- data: forwardData,
61
- params: forwardData,
62
- }
32
+ const req = event.node.req;
63
33
 
64
- if(documentLink=='avatar' ){
65
- axiosConfig.url = pathJoin([useRuntimeConfig().public.imageUrl, documentLink]);
66
- delete axiosConfig.params
67
- }
68
- // console.log("axiosConfig",axiosConfig)
69
- // if(key === 'system') {
70
- // axiosConfig.headers["X-Global"] = true;
71
- // delete axiosConfig.headers["X-Org"];
72
- // }
73
-
74
- // if(otherLink.includes('avatar')) {
75
- // axiosConfig.responseType = 'arraybuffer';
76
- // // axiosConfig.headers['Acceptable'] = 'text/html,image/avif,image/webp,image/apng';
77
- // }
78
-
79
- axios(axiosConfig).then((res) => {
80
- // console.log("RRes",res)
81
- if (res.headers['content-type'] === 'image/png') {
82
- // Set the response headers for the image
83
- frontEndRes.setHeader('Content-Type', 'image/png');
84
- frontEndRes.setHeader('Content-Disposition', 'inline');
85
-
86
- // Send the image data as the response body
87
- frontEndRes.end(Buffer.from(res.data, 'binary'));
88
- }else if(documentLink.includes('images/')){
89
- // console.log(documentLink," Resdata of base64 photo",res.data.length)
90
- let imageData
91
- frontEndRes.setHeader('Content-Type', 'image/png');
92
-
93
- // console.log("load image for",documentLink)
94
- if( res.data.length){
95
- // console.log("obtain base64 from server length:",res.data.length)
96
- imageData = base64ToBuffer(res.data);
97
-
98
- }else{
99
- // console.log("server no image, use default image")
100
- const folder = 'public/images/'
101
- let filename = ''
102
- if(documentLink.includes('student')) filename='student.png';
103
- else if(documentLink.includes('teacher')) filename='teacher.png';
104
- else if(documentLink.includes('organization')) filename='organization.png';
105
- else filename='unknown.png';
106
- const fullpath = folder+filename;
107
- // console.log("photo path",fullpath)
108
- if(fs.existsSync(fullpath)){
109
- imageData = fs.readFileSync(fullpath)
110
- }else{
111
- console.log(fullpath,'does not exists')
112
- }
113
- }
114
- frontEndRes.end(Buffer.from(imageData, 'binary'));
115
-
116
- } else {
117
- // For non-image responses, set the Content-Type header and send the response body
118
- // setHeader(event, 'Content-type', <string>res.headers['Content-Type']);
34
+ if (!accessToken || typeof accessToken !== "string") {
35
+ return sendRedirect(event, "/login", 302);
36
+ }
119
37
 
120
- frontEndRes.statusCode = res.status;
121
- if(res.statusText) {
122
- frontEndRes.statusMessage = res.statusText;
123
- }
38
+ if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH") {
39
+ forwardData = await readBody(event);
40
+ } else {
41
+ forwardData = getQuery(event);
42
+ }
124
43
 
125
- resolve(res.data);
44
+ // if(typeof forwardData === "object" && "_branch" in forwardData) {
45
+ // xOrg = xOrg + forwardData._branch;
46
+ // delete forwardData._branch;
47
+ // }
48
+
49
+ const frontEndRes = event.node.res;
50
+
51
+ const url = process.env.SIMPLEAPP_BACKEND_URL + `/profile/${documentLink}`;
52
+ // console.warn('backend server-----',req.method,url,forwardData)
53
+
54
+ const axiosConfig: any = {
55
+ method: req.method,
56
+ url: url,
57
+ headers: {
58
+ Authorization: `Bearer ${accessToken}`,
59
+ },
60
+ data: forwardData,
61
+ params: forwardData,
62
+ };
63
+
64
+ if (documentLink == "avatar") {
65
+ axiosConfig.url = pathJoin([
66
+ useRuntimeConfig().public.imageUrl,
67
+ documentLink,
68
+ ]);
69
+ delete axiosConfig.params;
70
+ }
71
+ // console.log("axiosConfig",axiosConfig)
72
+ // if(key === 'system') {
73
+ // axiosConfig.headers["X-Global"] = true;
74
+ // delete axiosConfig.headers["X-Org"];
75
+ // }
76
+
77
+ // if(otherLink.includes('avatar')) {
78
+ // axiosConfig.responseType = 'arraybuffer';
79
+ // // axiosConfig.headers['Acceptable'] = 'text/html,image/avif,image/webp,image/apng';
80
+ // }
81
+
82
+ axios(axiosConfig)
83
+ .then((res) => {
84
+ // console.log("RRes",res)
85
+ if (res.headers["content-type"] === "image/png") {
86
+ // Set the response headers for the image
87
+ frontEndRes.setHeader("Content-Type", "image/png");
88
+ frontEndRes.setHeader("Content-Disposition", "inline");
89
+
90
+ // Send the image data as the response body
91
+ frontEndRes.end(Buffer.from(res.data, "binary"));
92
+ } else if (documentLink.includes("images/")) {
93
+ // console.log(documentLink," Resdata of base64 photo",res.data.length)
94
+ let imageData;
95
+ frontEndRes.setHeader("Content-Type", "image/png");
96
+
97
+ // console.log("load image for",documentLink)
98
+ if (res.data.length) {
99
+ // console.log("obtain base64 from server length:",res.data.length)
100
+ imageData = base64ToBuffer(res.data);
101
+ } else {
102
+ // console.log("server no image, use default image")
103
+ const folder = "public/images/";
104
+ let filename = "";
105
+ if (documentLink.includes("student")) filename = "student.png";
106
+ else if (documentLink.includes("teacher")) filename = "teacher.png";
107
+ else if (documentLink.includes("organization"))
108
+ filename = "organization.png";
109
+ else filename = "unknown.png";
110
+ const fullpath = folder + filename;
111
+ // console.log("photo path",fullpath)
112
+ if (fs.existsSync(fullpath)) {
113
+ imageData = fs.readFileSync(fullpath);
114
+ } else {
115
+ console.log(fullpath, "does not exists");
126
116
  }
117
+ }
118
+ frontEndRes.end(Buffer.from(imageData, "binary"));
119
+ } else {
120
+ // For non-image responses, set the Content-Type header and send the response body
121
+ // setHeader(event, 'Content-type', <string>res.headers['Content-Type']);
127
122
 
128
- }).catch((error) => {
129
- if(!error?.response){
130
- console.log("backend server no response ",error.code)
131
- reject({
132
- statusMessage:"backendServerDownMessage",
133
- statusCode: 503,
134
- });
135
- }else{
136
-
137
- if (error.response?.status && error.response.status == 401) {
138
- // return sendRedirect(event, "/login", 401);
139
- reject({
140
- statusMessage: error.response.statusText,
141
- statusCode: 401,
142
- data: error.response.data,
143
- });
144
- return;
145
- }
146
- reject({
147
- statusMessage: error.response.statusText,
148
- statusCode: error.response.status ,
149
- data: error.response.data
150
- }); // resolve({ status: 'ok' })
151
- // throw createError({ statusMessage: 'Bad Requests', statusCode: 404 })
152
- }
153
- })
154
-
155
- // resolve({
156
- // status: 'ok'
157
- // })
158
- })
159
-
160
- })
161
-
162
-
163
-
164
- function base64ToBuffer(base64String:string) {
165
- // Split the base64 string into parts
166
- const parts = base64String.split(',');
167
- const contentType = parts[0].split(':')[1];
168
- const base64Data = parts[1];
169
-
170
- // Decode the base64 data
171
- const binaryString = atob(base64Data);
172
- const buffer = new Buffer.from(binaryString, 'binary');
173
-
174
- return buffer
175
- }
123
+ frontEndRes.statusCode = res.status;
124
+ if (res.statusText) {
125
+ frontEndRes.statusMessage = res.statusText;
126
+ }
127
+
128
+ resolve(res.data);
129
+ }
130
+ })
131
+ .catch((error) => {
132
+ if (!error?.response) {
133
+ console.log("backend server no response ", error.code);
134
+ reject({
135
+ statusMessage: "backendServerDownMessage",
136
+ statusCode: 503,
137
+ });
138
+ } else {
139
+ if (error.response?.status && error.response.status == 401) {
140
+ return sendRedirect(event, "/login", 302);
141
+ }
142
+ reject({
143
+ statusMessage: error.response.statusText,
144
+ statusCode: error.response.status,
145
+ data: error.response.data,
146
+ }); // resolve({ status: 'ok' })
147
+ // throw createError({ statusMessage: 'Bad Requests', statusCode: 404 })
148
+ }
149
+ });
150
+
151
+ // resolve({
152
+ // status: 'ok'
153
+ // })
154
+ });
155
+ });
156
+
157
+ function base64ToBuffer(base64String: string) {
158
+ // Split the base64 string into parts
159
+ const parts = base64String.split(",");
160
+ const contentType = parts[0].split(":")[1];
161
+ const base64Data = parts[1];
162
+
163
+ // Decode the base64 data
164
+ const binaryString = atob(base64Data);
165
+ const buffer = new Buffer.from(binaryString, "binary");
166
+
167
+ return buffer;
168
+ }
@@ -16,15 +16,13 @@ export default defineEventHandler(async (event:any) => {
16
16
 
17
17
  try {
18
18
  session = await getServerSession(event)
19
-
20
19
  } catch (error) {
21
- return sendRedirect(event, '/login', 401)
20
+ return sendRedirect(event, '/login', 302)
22
21
  }
23
22
 
24
23
  return new Promise<any>(async (resolve, reject) => {
25
24
  if(!session) {
26
- reject({ statusMessage: 'Unauthorized', statusCode: 401 });
27
- throw createError({ statusMessage: 'Unauthorized', statusCode: 401 })
25
+ return sendRedirect(event, '/login', 302)
28
26
  }
29
27
  const seperateSymbol = '.';
30
28
  const accessToken = session?.accessToken;
@@ -33,6 +31,10 @@ export default defineEventHandler(async (event:any) => {
33
31
 
34
32
  const req = event.node.req;
35
33
 
34
+ if (!accessToken || typeof accessToken !== 'string') {
35
+ return sendRedirect(event, '/login', 302);
36
+ }
37
+
36
38
  if(req.method == 'POST' || req.method == 'PUT' || req.method == 'PATCH') {
37
39
 
38
40
  forwardData = await readBody(event);
@@ -78,16 +80,13 @@ export default defineEventHandler(async (event:any) => {
78
80
  // console.log('#####################################')
79
81
  // console.log(axiosConfig);
80
82
  // console.log('#####################################')
81
- if (error.response?.status && error.response.status == '401') {
82
- //return reject({ statusMessage: 'Unauthorized', statusCode: 401 });
83
- return sendRedirect(event, '/login', 401)
84
- // throw createError({ statusMessage: 'Unauthorized', statusCode: 401 })
83
+ if (error.response?.status && error.response.status == 401) {
84
+ return sendRedirect(event, '/login', 302)
85
85
  }
86
86
 
87
- // reject(error.data)
88
- reject({
89
- statusMessage: error.response.statusText,
90
- statusCode: error.response.status ,
87
+ reject({
88
+ statusMessage: error.response.statusText,
89
+ statusCode: error.response.status,
91
90
  data: error.response.data
92
91
  }); // resolve({ status: 'ok' })
93
92
  // throw createError({ statusMessage: 'Bad Requests', statusCode: 404 })