@simitgroup/simpleapp-generator 2.0.0-u-alpha → 2.0.0-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 (28) hide show
  1. package/ReleaseNote.md +10 -0
  2. package/package.json +1 -1
  3. package/templates/basic/miniApi/resource.controller.ts.eta +14 -0
  4. package/templates/basic/miniApi/resource.service.ts.eta +6 -0
  5. package/templates/basic/nest/controller.ts.eta +70 -76
  6. package/templates/basic/nuxt/pages.form.vue.eta +2 -2
  7. package/templates/basic/nuxt/pages.landing.vue.eta +2 -2
  8. package/templates/miniApi/src/constants/api-scopes.ts.eta +18 -0
  9. package/templates/nest/src/main.ts._eta +14 -19
  10. package/templates/nest/src/simple-app/_core/features/user-context/user.context.ts.eta +1 -4
  11. package/templates/nest/src/simple-app/_core/framework/base/simple-app.controller.ts.eta +12 -2
  12. package/templates/nest/src/simple-app/_core/framework/base/simple-app.service.ts.eta +3 -4
  13. package/templates/nuxt/components/simpleApp/SimpleAppFormToolBar.vue._eta +1 -1
  14. package/templates/nuxt/server/api/[xorg]/[...].ts._eta +76 -121
  15. package/templates/nest/src/simple-app/features/print/api/.gitignore.eta +0 -4
  16. package/templates/nest/src/simple-app/features/print/api/.npmignore.eta +0 -1
  17. package/templates/nest/src/simple-app/features/print/api/.openapi-generator/FILES.eta +0 -8
  18. package/templates/nest/src/simple-app/features/print/api/.openapi-generator/VERSION.eta +0 -1
  19. package/templates/nest/src/simple-app/features/print/api/.openapi-generator-ignore.eta +0 -23
  20. package/templates/nest/src/simple-app/features/print/api/api.ts.eta +0 -223
  21. package/templates/nest/src/simple-app/features/print/api/base.ts.eta +0 -86
  22. package/templates/nest/src/simple-app/features/print/api/common.ts.eta +0 -150
  23. package/templates/nest/src/simple-app/features/print/api/configuration.ts.eta +0 -110
  24. package/templates/nest/src/simple-app/features/print/api/git_push.sh.eta +0 -57
  25. package/templates/nest/src/simple-app/features/print/api/index.ts.eta +0 -18
  26. package/templates/nest/src/simple-app/features/print/api/openapitools.json.eta +0 -7
  27. package/templates/nest/src/simple-app/features/print/print.module.ts.eta +0 -15
  28. package/templates/nest/src/simple-app/features/print/print.service.ts.eta +0 -41
@@ -5,128 +5,83 @@
5
5
  * Author: Ks Tan
6
6
  */
7
7
 
8
-
9
- import axios, { AxiosRequestConfig } from 'axios';
10
- import { getServerSession } from '#auth'
11
- import type { Session } from 'next-auth';
12
- import * as fs from 'fs'
13
- export default defineEventHandler(async (event:any) => {
14
- type additionalprops = {accessToken?:string}
15
- let session:any=null
16
-
17
-
18
- try {
19
- session = await getServerSession(event)
20
-
21
- } catch (error) {
22
- throw createError({ statusText: 'Unauthorized', status: 302 })
23
- }
24
- if(!session) {
25
- throw createError({ statusText: 'Unauthorized', status: 302 })
26
- }
27
-
28
- return new Promise<any>(async (resolve, reject) => {
29
- const xOrg = event.context.params?.xorg ?? ''
30
- const documentLink = event.context.params?._ ?? ''
31
- const accessToken = session?.accessToken;
32
-
8
+ import axios, { AxiosRequestConfig } from "axios";
9
+ import { getServerSession } from "#auth";
10
+ export default defineEventHandler(async (event: any) => {
11
+ let session: any = null;
12
+ try {
13
+ session = await getServerSession(event);
14
+ } catch (error) {
15
+ throw createError({ statusText: "Unauthorized", status: 302 });
16
+ }
17
+ if (!session) {
18
+ throw createError({ statusText: "Unauthorized", status: 302 });
19
+ }
33
20
 
34
- let forwardData: any = {};
35
- const req = event.node.req;
36
- let bodydata: any
37
- let querydata:any
38
- querydata = getQuery(event);
39
- if(req.method == 'POST' || req.method == 'PUT' || req.method == 'PATCH' ) {
40
- bodydata = await readBody(event);
41
- }
21
+ return new Promise<any>(async (resolve, reject) => {
22
+ const xOrg = event.context.params?.xorg ?? "";
23
+ const documentLink = event.context.params?._ ?? "";
24
+ const accessToken = session?.accessToken;
25
+ const req = event.node.req;
26
+ let bodydata: any;
27
+ let querydata: any;
28
+ querydata = getQuery(event);
29
+ if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH") {
30
+ bodydata = await readBody(event);
31
+ }
42
32
 
33
+ const frontEndRes = event.node.res;
34
+ const url = process.env.SIMPLEAPP_BACKEND_URL + "/" + documentLink;
35
+ const axiosConfig: AxiosRequestConfig = {
36
+ method: req.method,
37
+ url: url,
38
+ headers: {
39
+ Authorization: `Bearer ${accessToken}`,
40
+ "X-Org": xOrg,
41
+ "X-Mini-App-Code": event.headers.get("x-mini-app-code"),
42
+ "x-mini-app-dev-portal-app-id": event.headers.get(
43
+ "x-mini-app-dev-portal-app-id",
44
+ ),
45
+ },
46
+ data: bodydata,
47
+ params: querydata,
48
+ };
43
49
 
44
- const frontEndRes = event.node.res;
45
- const url = process.env.SIMPLEAPP_BACKEND_URL + '/' + documentLink;
46
- const axiosConfig: AxiosRequestConfig = {
47
- method: req.method,
48
- url: url,
49
- headers: {
50
- Authorization: `Bearer ${accessToken}`,
51
- 'X-Org': xOrg,
52
- },
53
- data: bodydata,
54
- params: querydata,
55
- }
56
-
57
- try{
58
- const res = await axios(axiosConfig)
59
- if (res.headers['content-type'] === 'image/png') {
60
- frontEndRes.setHeader('Content-Type', 'image/png');
61
- frontEndRes.setHeader('Content-Disposition', 'inline');
62
- frontEndRes.end(Buffer.from(res.data, 'binary'));
63
- }else if(documentLink.includes('images/')){
64
- // console.log(documentLink," Resdata of base64 photo",res.data.length)
65
- let imageData
66
- frontEndRes.setHeader('Content-Type', 'image/png');
67
-
68
- // console.log("load image for",documentLink)
69
- if( res.data.length){
70
- console.log("obtain base64 from server length:",res.data.length)
71
- imageData = base64ToBuffer(res.data);
72
-
73
- }else{
74
- // console.log("server no image, use default image")
75
- const folder = 'assets/images/'
76
- let filename = filename='unknown.png';
77
- const fullpath = folder+filename;
78
- if(fs.existsSync(fullpath)){
79
- imageData = fs.readFileSync(fullpath)
80
- }else{
81
- console.log(fullpath,'does not exists')
82
- }
83
- }
84
- frontEndRes.end(Buffer.from(imageData, 'binary'));
85
-
86
- }else{
87
- frontEndRes.statusCode = res.status;
88
- if(res.statusText) {
89
- frontEndRes.statusMessage = res.statusText;
90
- }
91
- resolve(res.data);
92
- }
93
- }catch(error){
94
- if(!error?.response){
95
- console.log("backend server no response ",error.code)
96
- reject({
97
- statusMessage:"backendServerDownMessage",
98
- statusCode: 503,
99
- });
100
- }else if (error.response.status == 401) {
101
- return sendRedirect(event, '/login', 302)
102
- }else{
103
- const responseCode = error.response.data?.statusCode ? error.response.data.statusCode : error.response.status
104
- const responseMsg = error.response.data ? error.response.data.message : error.response.statusText
105
- // reject(error.data)
106
- // console.log("----error.response.data--",responseMsg,error.response.data,error.response.status,responseCode)
107
- reject({
108
- statusMessage: responseMsg,
109
- statusCode: responseCode ,
110
- data: error.response.data
111
- });
112
-
113
- }
50
+ try {
51
+ const res = await axios(axiosConfig);
52
+ for(const k of Object.keys(res.headers)){
53
+ frontEndRes.setHeader[k]=res.headers[k]
54
+ }
55
+ frontEndRes.statusCode = res.status;
56
+ if (res.statusText) {
57
+ frontEndRes.statusMessage = res.statusText;
114
58
  }
115
- })
116
-
117
- })
118
-
119
-
120
-
121
- function base64ToBuffer(base64String:string) {
122
- // Split the base64 string into parts
123
- const parts = base64String.split(',');
124
- const contentType = parts[0].split(':')[1];
125
- const base64Data = parts[1];
126
-
127
- // Decode the base64 data
128
- const binaryString = atob(base64Data);
129
- const buffer = new Buffer.from(binaryString, 'binary');
130
-
131
- return buffer
132
- }
59
+ resolve(res.data);
60
+ } catch (error:any) {
61
+ console.log("Axios error", error.code, error);
62
+ if (!error?.response) {
63
+ console.log("backend server no response ", error.code);
64
+ reject({
65
+ statusMessage: "backendServerDownMessage",
66
+ statusCode: 503,
67
+ });
68
+ } else if (error.response.status == 401) {
69
+ return sendRedirect(event, "/login", 302);
70
+ } else {
71
+ const responseCode = error.response.data?.statusCode
72
+ ? error.response.data.statusCode
73
+ : error.response.status;
74
+ const responseMsg = error.response.data
75
+ ? error.response.data.message
76
+ : error.response.statusText;
77
+ // reject(error.data)
78
+ // console.log("----error.response.data--",responseMsg,error.response.data,error.response.status,responseCode)
79
+ reject({
80
+ statusMessage: responseMsg,
81
+ statusCode: responseCode,
82
+ data: error.response.data,
83
+ });
84
+ }
85
+ }
86
+ });
87
+ });
@@ -1,4 +0,0 @@
1
- wwwroot/*.js
2
- node_modules
3
- typings
4
- dist
@@ -1 +0,0 @@
1
- # empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
@@ -1,8 +0,0 @@
1
- .gitignore
2
- .npmignore
3
- api.ts
4
- base.ts
5
- common.ts
6
- configuration.ts
7
- git_push.sh
8
- index.ts
@@ -1,23 +0,0 @@
1
- # OpenAPI Generator Ignore
2
- # Generated by openapi-generator https://github.com/openapitools/openapi-generator
3
-
4
- # Use this file to prevent files from being overwritten by the generator.
5
- # The patterns follow closely to .gitignore or .dockerignore.
6
-
7
- # As an example, the C# client generator defines ApiClient.cs.
8
- # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9
- #ApiClient.cs
10
-
11
- # You can match any string of characters against a directory, file or extension with a single asterisk (*):
12
- #foo/*/qux
13
- # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14
-
15
- # You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16
- #foo/**/qux
17
- # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18
-
19
- # You can also negate patterns with an exclamation (!).
20
- # For example, you can ignore all files in a docs folder with the file extension .md:
21
- #docs/*.md
22
- # Then explicitly reverse the ignore rule for a single file:
23
- #!docs/README.md
@@ -1,223 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * prinf format microservice
5
- * print format microservice
6
- *
7
- * The version of the OpenAPI document: 1.0.0
8
- * Contact: kstan@simitgroup.com
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
-
15
-
16
- import type { Configuration } from './configuration';
17
- import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
18
- import globalAxios from 'axios';
19
- // Some imports not used depending on template conditions
20
- // @ts-ignore
21
- import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
22
- import type { RequestArgs } from './base';
23
- // @ts-ignore
24
- import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerMap } from './base';
25
-
26
-
27
- /**
28
- * DefaultApi - axios parameter creator
29
- * @export
30
- */
31
- export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) {
32
- return {
33
- /**
34
- * generate pdf
35
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
36
- * @param {string} id data _id
37
- * @param {*} [options] Override http request option.
38
- * @throws {RequiredError}
39
- */
40
- runPdf: async (formatid: string, id: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
41
- // verify required parameter 'formatid' is not null or undefined
42
- assertParamExists('runPdf', 'formatid', formatid)
43
- // verify required parameter 'id' is not null or undefined
44
- assertParamExists('runPdf', 'id', id)
45
- const localVarPath = `/api/print/{formatid}/{id}`
46
- .replace(`{${"formatid"}}`, encodeURIComponent(String(formatid)))
47
- .replace(`{${"id"}}`, encodeURIComponent(String(id)));
48
- // use dummy base URL string because the URL constructor only accepts absolute URLs.
49
- const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
50
- let baseOptions;
51
- if (configuration) {
52
- baseOptions = configuration.baseOptions;
53
- }
54
-
55
- const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
56
- const localVarHeaderParameter = {} as any;
57
- const localVarQueryParameter = {} as any;
58
-
59
- // authentication simbiz_auth required
60
- // oauth required
61
- await setOAuthToObject(localVarHeaderParameter, "simbiz_auth", [], configuration)
62
-
63
- // authentication apiKey required
64
- await setApiKeyToObject(localVarHeaderParameter, "x-org", configuration)
65
-
66
-
67
-
68
- setSearchParams(localVarUrlObj, localVarQueryParameter);
69
- let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
70
- localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
71
-
72
- return {
73
- url: toPathString(localVarUrlObj),
74
- options: localVarRequestOptions,
75
- };
76
- },
77
- /**
78
- * Generate base64 pdf string
79
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
80
- * @param {string} id data _id
81
- * @param {*} [options] Override http request option.
82
- * @throws {RequiredError}
83
- */
84
- runPdfBase64: async (formatid: string, id: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
85
- // verify required parameter 'formatid' is not null or undefined
86
- assertParamExists('runPdfBase64', 'formatid', formatid)
87
- // verify required parameter 'id' is not null or undefined
88
- assertParamExists('runPdfBase64', 'id', id)
89
- const localVarPath = `/api/print/{formatid}/{id}/base64`
90
- .replace(`{${"formatid"}}`, encodeURIComponent(String(formatid)))
91
- .replace(`{${"id"}}`, encodeURIComponent(String(id)));
92
- // use dummy base URL string because the URL constructor only accepts absolute URLs.
93
- const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
94
- let baseOptions;
95
- if (configuration) {
96
- baseOptions = configuration.baseOptions;
97
- }
98
-
99
- const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
100
- const localVarHeaderParameter = {} as any;
101
- const localVarQueryParameter = {} as any;
102
-
103
- // authentication simbiz_auth required
104
- // oauth required
105
- await setOAuthToObject(localVarHeaderParameter, "simbiz_auth", [], configuration)
106
-
107
- // authentication apiKey required
108
- await setApiKeyToObject(localVarHeaderParameter, "x-org", configuration)
109
-
110
-
111
-
112
- setSearchParams(localVarUrlObj, localVarQueryParameter);
113
- let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
114
- localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
115
-
116
- return {
117
- url: toPathString(localVarUrlObj),
118
- options: localVarRequestOptions,
119
- };
120
- },
121
- }
122
- };
123
-
124
- /**
125
- * DefaultApi - functional programming interface
126
- * @export
127
- */
128
- export const DefaultApiFp = function(configuration?: Configuration) {
129
- const localVarAxiosParamCreator = DefaultApiAxiosParamCreator(configuration)
130
- return {
131
- /**
132
- * generate pdf
133
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
134
- * @param {string} id data _id
135
- * @param {*} [options] Override http request option.
136
- * @throws {RequiredError}
137
- */
138
- async runPdf(formatid: string, id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<File>> {
139
- const localVarAxiosArgs = await localVarAxiosParamCreator.runPdf(formatid, id, options);
140
- const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
141
- const localVarOperationServerBasePath = operationServerMap['DefaultApi.runPdf']?.[localVarOperationServerIndex]?.url;
142
- return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
143
- },
144
- /**
145
- * Generate base64 pdf string
146
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
147
- * @param {string} id data _id
148
- * @param {*} [options] Override http request option.
149
- * @throws {RequiredError}
150
- */
151
- async runPdfBase64(formatid: string, id: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<File>> {
152
- const localVarAxiosArgs = await localVarAxiosParamCreator.runPdfBase64(formatid, id, options);
153
- const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
154
- const localVarOperationServerBasePath = operationServerMap['DefaultApi.runPdfBase64']?.[localVarOperationServerIndex]?.url;
155
- return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
156
- },
157
- }
158
- };
159
-
160
- /**
161
- * DefaultApi - factory interface
162
- * @export
163
- */
164
- export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
165
- const localVarFp = DefaultApiFp(configuration)
166
- return {
167
- /**
168
- * generate pdf
169
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
170
- * @param {string} id data _id
171
- * @param {*} [options] Override http request option.
172
- * @throws {RequiredError}
173
- */
174
- runPdf(formatid: string, id: string, options?: any): AxiosPromise<File> {
175
- return localVarFp.runPdf(formatid, id, options).then((request) => request(axios, basePath));
176
- },
177
- /**
178
- * Generate base64 pdf string
179
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
180
- * @param {string} id data _id
181
- * @param {*} [options] Override http request option.
182
- * @throws {RequiredError}
183
- */
184
- runPdfBase64(formatid: string, id: string, options?: any): AxiosPromise<File> {
185
- return localVarFp.runPdfBase64(formatid, id, options).then((request) => request(axios, basePath));
186
- },
187
- };
188
- };
189
-
190
- /**
191
- * DefaultApi - object-oriented interface
192
- * @export
193
- * @class DefaultApi
194
- * @extends {BaseAPI}
195
- */
196
- export class DefaultApi extends BaseAPI {
197
- /**
198
- * generate pdf
199
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
200
- * @param {string} id data _id
201
- * @param {*} [options] Override http request option.
202
- * @throws {RequiredError}
203
- * @memberof DefaultApi
204
- */
205
- public runPdf(formatid: string, id: string, options?: RawAxiosRequestConfig) {
206
- return DefaultApiFp(this.configuration).runPdf(formatid, id, options).then((request) => request(this.axios, this.basePath));
207
- }
208
-
209
- /**
210
- * Generate base64 pdf string
211
- * @param {string} formatid format name, can be invoice,purchaseorder, or formatid like xxxx-yyy-zzz-xxx in database
212
- * @param {string} id data _id
213
- * @param {*} [options] Override http request option.
214
- * @throws {RequiredError}
215
- * @memberof DefaultApi
216
- */
217
- public runPdfBase64(formatid: string, id: string, options?: RawAxiosRequestConfig) {
218
- return DefaultApiFp(this.configuration).runPdfBase64(formatid, id, options).then((request) => request(this.axios, this.basePath));
219
- }
220
- }
221
-
222
-
223
-
@@ -1,86 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * prinf format microservice
5
- * print format microservice
6
- *
7
- * The version of the OpenAPI document: 1.0.0
8
- * Contact: kstan@simitgroup.com
9
- *
10
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
- * https://openapi-generator.tech
12
- * Do not edit the class manually.
13
- */
14
-
15
-
16
- import type { Configuration } from './configuration';
17
- // Some imports not used depending on template conditions
18
- // @ts-ignore
19
- import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
20
- import globalAxios from 'axios';
21
-
22
- export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
23
-
24
- /**
25
- *
26
- * @export
27
- */
28
- export const COLLECTION_FORMATS = {
29
- csv: ",",
30
- ssv: " ",
31
- tsv: "\t",
32
- pipes: "|",
33
- };
34
-
35
- /**
36
- *
37
- * @export
38
- * @interface RequestArgs
39
- */
40
- export interface RequestArgs {
41
- url: string;
42
- options: RawAxiosRequestConfig;
43
- }
44
-
45
- /**
46
- *
47
- * @export
48
- * @class BaseAPI
49
- */
50
- export class BaseAPI {
51
- protected configuration: Configuration | undefined;
52
-
53
- constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
54
- if (configuration) {
55
- this.configuration = configuration;
56
- this.basePath = configuration.basePath ?? basePath;
57
- }
58
- }
59
- };
60
-
61
- /**
62
- *
63
- * @export
64
- * @class RequiredError
65
- * @extends {Error}
66
- */
67
- export class RequiredError extends Error {
68
- constructor(public field: string, msg?: string) {
69
- super(msg);
70
- this.name = "RequiredError"
71
- }
72
- }
73
-
74
- interface ServerMap {
75
- [key: string]: {
76
- url: string,
77
- description: string,
78
- }[];
79
- }
80
-
81
- /**
82
- *
83
- * @export
84
- */
85
- export const operationServerMap: ServerMap = {
86
- }