@simitgroup/simpleapp-generator 1.6.6-n-alpha → 1.6.6-p-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 (48) hide show
  1. package/ReleaseNote.md +3 -0
  2. package/dist/buildinschemas/customfield.d.ts.map +1 -1
  3. package/dist/buildinschemas/customfield.js +13 -2
  4. package/dist/buildinschemas/customfield.js.map +1 -1
  5. package/dist/framework.d.ts +2 -0
  6. package/dist/framework.d.ts.map +1 -1
  7. package/dist/framework.js +94 -57
  8. package/dist/framework.js.map +1 -1
  9. package/dist/generate.d.ts.map +1 -1
  10. package/dist/generate.js +160 -34
  11. package/dist/generate.js.map +1 -1
  12. package/dist/index.js +30 -12
  13. package/dist/index.js.map +1 -1
  14. package/dist/type.d.ts +5 -0
  15. package/dist/type.d.ts.map +1 -1
  16. package/dist/type.js.map +1 -1
  17. package/package.json +1 -1
  18. package/src/buildinschemas/customfield.ts +14 -3
  19. package/src/framework.ts +309 -251
  20. package/src/generate.ts +592 -434
  21. package/src/index.ts +136 -118
  22. package/src/type.ts +5 -0
  23. package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +117 -0
  24. package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +213 -0
  25. package/templates/basic/nest/apischema.ts.eta +56 -27
  26. package/templates/basic/nest/controller.ts.eta +2 -1
  27. package/templates/basic/nest/type.ts.eta +28 -10
  28. package/templates/basic/nuxt/resource-bridge.service.ts.eta +162 -0
  29. package/templates/miniAppJsSdk/src/index.ts.eta +28 -0
  30. package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +70 -0
  31. package/templates/miniAppJsSdk/src/services/bridge.service.ts.eta +91 -0
  32. package/templates/miniAppJsSdk/src/types/service.type.ts.eta +22 -0
  33. package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +73 -0
  34. package/templates/nest/src/simpleapp/apischemas/customfield.ts.eta +21 -0
  35. package/templates/nest/src/simpleapp/generate/jsonschemas/index.ts.eta +11 -0
  36. package/templates/nest/src/simpleapp/types/customfield.ts.eta +14 -0
  37. package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +2 -3
  38. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +13 -12
  39. package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +122 -125
  40. package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/common.constant.ts.eta +15 -0
  41. package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/resource.constant.ts.eta +46 -0
  42. package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +63 -0
  43. package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge.service.ts.eta +110 -0
  44. package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/bridge.type.ts.eta +72 -0
  45. package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/resource-mapper.type.ts.eta +55 -0
  46. package/templates/nuxt/types/others.ts.eta +74 -65
  47. package/templates/nuxt/types/schema.ts.eta +225 -188
  48. package/templates/project/build.sh.eta +9 -0
@@ -77,23 +77,24 @@ export class SimpleAppClient<
77
77
  } //if there is readonly attribute in data, will override it at processor and client
78
78
  setData = (data: any) => {
79
79
  // this.data.value = data;
80
- // TODO: TS ERROR
81
- data.more = this._customFieldClient.processCustomFieldData(
82
- // @ts-ignore
83
- this.schema.properties?.["more"],
84
- data.createdBy == "",
85
- data.more,
86
- );
80
+
81
+ // TODO: Will Cause Docno Format Broken
82
+ // data.more = this._customFieldClient.formCustomFieldData(
83
+ // this.doctype,
84
+ // this.schema.properties?.more,
85
+ // data.createdBy == "",
86
+ // data.more,
87
+ // );
87
88
 
88
89
  Object.assign(this.data.value, data);
89
90
  };
90
91
 
91
92
  async processCustomField() {
92
- const resp = this._customFieldClient.processCustomField(this.doctype);
93
- // TODO: TS ERROR
94
- // @ts-ignore
95
- this.schema.properties.more = resp.schema;
96
- this.setData(this.data.value);
93
+ // const resp = this._customFieldClient.formCustomFieldJsonSchema(
94
+ // this.doctype,
95
+ // );
96
+ // this.schema.properties.more = resp;
97
+ // this.setData(this.data.value);
97
98
  }
98
99
 
99
100
  async getById(id?: string) {
@@ -3,74 +3,62 @@
3
3
  * MODIFICATION OVERRIDE BY GENERATEOR
4
4
  * last change 2025-06-09
5
5
  */
6
- import { isEmpty } from "lodash";
6
+ import _ from "lodash";
7
7
  import {
8
- CustomFieldItemJsonSchema,
9
- CustomFieldJsonSchema,
10
- SimpleAppJSONSchema7,
8
+ CustomFieldJsonSchemaMoreSchema,
9
+ CustomFieldJsonSchemaMoreSchemaGroup,
10
+ DynamicObject,
11
+ SimpleAppJSONSchema7Definition,
11
12
  } from "~/types";
12
13
 
13
- export type CustomFieldMoreDataGroup = {
14
- [key: string]: CustomFieldMoreDataGroupItem;
15
- };
14
+ export class SimpleAppCustomFieldClient {
15
+ constructor() {}
16
16
 
17
- export type CustomFieldMoreDataGroupItem = {
18
- [key: string]: any;
19
- };
17
+ formCustomFieldJsonSchema(collectionName: string) {
18
+ const customFieldFromDB = this._findCustomFieldSchemaFromDB(collectionName);
19
+ const customFieldFromPlugin =
20
+ this._findCustomFieldSchemaFromPlugin(collectionName);
20
21
 
21
- export class SimpleAppCustomFieldClient {
22
- private _defaultReturn = {
23
- schema: {
22
+ if (customFieldFromDB && !_.isEmpty(customFieldFromDB)) {
23
+ }
24
+
25
+ const schema: CustomFieldJsonSchemaMoreSchema = {
24
26
  type: "object",
25
- properties: {},
26
- },
27
- };
27
+ properties: {
28
+ ...customFieldFromDB,
29
+ ...customFieldFromPlugin,
30
+ },
31
+ };
28
32
 
29
- constructor() {}
33
+ return schema;
34
+ }
30
35
 
31
- processCustomField(collectionName: string) {
32
- // console.log(collectionName, "trigger processCustomField");
36
+ private _findCustomFieldSchemaFromDB(collectionName: string) {
33
37
  const { $customFieldStore } = useNuxtApp();
34
- if (!$customFieldStore.data || isEmpty($customFieldStore.data)) {
35
- // Not Found Any Custom Field
36
- return this._defaultReturn;
38
+ if (!$customFieldStore.data || _.isEmpty($customFieldStore.data)) {
39
+ return {};
37
40
  }
38
41
 
39
42
  const customField = $customFieldStore.findByCollectionName(collectionName);
40
43
  if (!customField) {
41
- // Not Found Custom Field In Current collectionName
42
- return this._defaultReturn;
44
+ return {};
43
45
  }
44
46
 
45
- const schema = this._processCustomFieldMoreProperties(
46
- collectionName,
47
- customField.form.schema as CustomFieldItemJsonSchema,
48
- );
49
-
50
- return { schema };
51
- }
52
-
53
- private _processCustomFieldMoreProperties(
54
- collectionName: string,
55
- customFieldJsonSchemaString: CustomFieldItemJsonSchema | undefined,
56
- ) {
57
- const customFieldJsonSchema = this._processCustomFieldProperties(
58
- customFieldJsonSchemaString,
59
- );
60
- const pluginJsonSchema =
61
- this._processPluginCustomFieldProperties(collectionName);
62
- return {
63
- type: "object",
64
- properties: {
65
- ...customFieldJsonSchema,
66
- ...pluginJsonSchema,
47
+ const schema: CustomFieldJsonSchemaMoreSchemaGroup = {
48
+ default: {
49
+ title: "Custom Field",
50
+ ...customField.form.schema,
67
51
  },
68
52
  };
53
+
54
+ return schema;
69
55
  }
70
56
 
71
- private _processPluginCustomFieldProperties(collectionName: string) {
72
- const schema: CustomFieldJsonSchema["properties"] = {};
57
+ private _findCustomFieldSchemaFromPlugin(collectionName: string) {
58
+ const schema: CustomFieldJsonSchemaMoreSchemaGroup = {};
59
+
73
60
  const { $appPluginsStore } = useNuxtApp();
61
+
74
62
  const pluginForms = $appPluginsStore.getForm(collectionName);
75
63
  if (!pluginForms || pluginForms.length <= 0) {
76
64
  return schema;
@@ -80,112 +68,121 @@ export class SimpleAppCustomFieldClient {
80
68
  const pluginItem = pluginForms[i];
81
69
  const { pluginCode, jsonSchema } = pluginItem;
82
70
 
83
- schema[pluginCode] = jsonSchema as CustomFieldItemJsonSchema;
71
+ schema[pluginCode] = jsonSchema as SimpleAppJSONSchema7Definition;
84
72
  }
85
73
 
86
74
  return schema;
87
75
  }
88
76
 
89
- private _processCustomFieldProperties(
90
- customFieldJsonSchemaString: CustomFieldItemJsonSchema | undefined,
91
- ) {
92
- if (!customFieldJsonSchemaString) {
93
- return this._defaultReturn;
94
- }
95
-
96
- return {
97
- default: {
98
- title: "Custom Field",
99
- ...customFieldJsonSchemaString,
100
- },
101
- };
102
- }
103
-
104
- processCustomFieldData(
105
- moreSchema: CustomFieldJsonSchema | undefined,
77
+ formCustomFieldData(
78
+ collectionName: string,
79
+ moreSchema: CustomFieldJsonSchemaMoreSchema | undefined,
106
80
  isNew: boolean,
107
- resourceData: CustomFieldMoreDataGroup | undefined,
81
+ resourceData: any | undefined,
108
82
  ) {
109
- const data: Record<string, any> = {};
110
83
  if (!moreSchema || !moreSchema?.properties) {
111
- return data;
84
+ return resourceData;
112
85
  }
113
86
 
114
- for (const [groupName, groupItem] of Object.entries(
115
- moreSchema.properties,
116
- )) {
117
- let groupData: Record<string, any> = {};
118
- if (groupItem.properties) {
119
- groupData = this._processGroupItemData(
120
- groupItem.properties,
121
- isNew,
122
- resourceData?.[groupName],
123
- );
124
- }
125
-
126
- data[groupName] = groupData;
87
+ if (collectionName !== "religion") {
88
+ return resourceData;
127
89
  }
128
90
 
129
- return data;
130
- }
131
-
132
- private _processGroupItemData(
133
- groupItemProp: SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined,
134
- isNew: boolean,
135
- resourceData: CustomFieldMoreDataGroupItem | undefined,
136
- ) {
137
- const data: Record<string, any> = {};
91
+ const data: DynamicObject = {};
138
92
 
139
- if (!groupItemProp) {
140
- return data;
141
- }
93
+ if (!isNew) {
94
+ for (const [groupName, groupItem] of Object.entries(
95
+ moreSchema.properties,
96
+ )) {
97
+ const defaultData = this.generateDefaultData(groupItem);
98
+ const mergedData = this.mergeWithDefault(
99
+ defaultData,
100
+ resourceData?.[groupName],
101
+ );
142
102
 
143
- for (const [fieldName, fieldItem] of Object.entries(groupItemProp)) {
144
- let value;
145
- if (isNew) {
146
- // New Record
147
- value = this._getFieldDefaultValue(fieldItem);
148
- } else {
149
- // Fetch By Id
150
- if (resourceData?.[fieldName]) {
151
- // DB got this field
152
- value = resourceData?.[fieldName];
153
- } else {
154
- // DB don't have this field
155
- value = this._getDefaultValueByType(fieldItem);
156
- console.log(fieldName, value);
157
- }
103
+ data[groupName] = mergedData;
158
104
  }
105
+ } else {
106
+ for (const [groupName, groupItem] of Object.entries(
107
+ moreSchema.properties,
108
+ )) {
109
+ const defaultData = this.generateDefaultData(groupItem);
159
110
 
160
- data[fieldName] = value;
111
+ data[groupName] = defaultData;
112
+ }
161
113
  }
162
114
 
163
115
  return data;
164
116
  }
165
117
 
166
- private _getFieldDefaultValue(fieldItem: SimpleAppJSONSchema7) {
167
- return fieldItem.default !== undefined
168
- ? fieldItem.default
169
- : this._getDefaultValueByType(fieldItem);
170
- }
118
+ generateDefaultData(schema: any): any {
119
+ if (schema.type === "object") {
120
+ const result: any = {};
121
+ if (schema?.["x-foreignkey"]) {
122
+ return undefined;
123
+ }
171
124
 
172
- private _getDefaultValueByType(fieldItem: SimpleAppJSONSchema7) {
173
- if (fieldItem.type === "string") {
174
- return "";
125
+ const properties = schema.properties || {};
126
+ for (const key of Object.keys(properties)) {
127
+ result[key] = this.generateDefaultData(properties[key]);
128
+ }
129
+ return result;
175
130
  }
176
131
 
177
- if (fieldItem.type === "number") {
178
- return 0;
132
+ if (schema.type === "array") {
133
+ const itemSchema = schema.items;
134
+ const minItems = schema.minItems || 0;
135
+ const arr = [];
136
+ const itemsCount = minItems > 0 ? 1 : 0;
137
+ for (let i = 0; i < itemsCount; i++) {
138
+ arr.push(this.generateDefaultData(itemSchema));
139
+ }
140
+ return arr;
179
141
  }
180
142
 
181
- if (fieldItem.type === "object") {
182
- return {};
143
+ if (typeof schema.default !== "undefined") {
144
+ return schema.default;
183
145
  }
184
146
 
185
- if (fieldItem.type === "array") {
186
- return [];
147
+ // handle primitive types fallback
148
+ switch (schema.type) {
149
+ case "string":
150
+ return "";
151
+ case "number":
152
+ case "integer":
153
+ return 0;
154
+ case "boolean":
155
+ return false;
156
+ default:
157
+ return null;
187
158
  }
159
+ }
188
160
 
189
- return "";
161
+ mergeWithDefault(defaultData: any, dbData: any): any {
162
+ if (Array.isArray(defaultData)) {
163
+ if (Array.isArray(dbData)) {
164
+ if (_.isEmpty(dbData)) {
165
+ return [];
166
+ }
167
+ // Merge each item
168
+ const mergedArray = dbData.map((dbItem, index) => {
169
+ const defaultItem = defaultData[index] ?? defaultData[0]; // use first default if index out of bound
170
+ return this.mergeWithDefault(defaultItem, dbItem);
171
+ });
172
+ return mergedArray;
173
+ } else {
174
+ // return defaultData;
175
+ return [];
176
+ }
177
+ } else if (typeof defaultData === "object" && defaultData !== null) {
178
+ const result: any = {};
179
+ for (const key of Object.keys(defaultData)) {
180
+ result[key] = this.mergeWithDefault(defaultData[key], dbData?.[key]);
181
+ }
182
+ return result;
183
+ } else {
184
+ // primitive value
185
+ return typeof dbData !== "undefined" ? dbData : defaultData;
186
+ }
190
187
  }
191
188
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2025-06-18
5
+ * Author: --
6
+ */
7
+
8
+ export enum MINI_APP_BRIDGE_MESSAGES {
9
+ NAVIGATE = "NAVIGATE",
10
+ OPEN_ON_SCREEN_RESOURCE_FORM = "OPEN_ON_SCREEN_RESOURCE_FORM",
11
+ API = "API",
12
+ API_RESPONSE = "API_RESPONSE",
13
+ INIT = "INIT",
14
+ INIT_RESPONSE = "INIT_RESPONSE",
15
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2025-06-18
5
+ * Author: --
6
+ */
7
+
8
+ <%
9
+ const upperFirstCase = (value) => {
10
+ return value.charAt(0).toUpperCase() + value.slice(1);
11
+ }
12
+
13
+ const camelToKebab = (value) => {
14
+ return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
15
+ }
16
+
17
+ const getMiniAppInfo = (module) => {
18
+ const config = module.schema['x-simpleapp-config'];
19
+ const resourceName = config?.resourceName ?? config.documentName;
20
+
21
+ const pascalName = upperFirstCase(resourceName);
22
+ const kebabName = camelToKebab(resourceName);
23
+
24
+ const miniAppWhitelistApis = config?.miniApp?.whitelist || [];
25
+ const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
26
+
27
+ return {
28
+ resourceName,
29
+ pascalName,
30
+ kebabName,
31
+ hasMiniAppWhitelistedApi,
32
+ miniAppWhitelistApis,
33
+ }
34
+ }
35
+ %>
36
+
37
+ export const MINI_APP_API_RESOURCES = [
38
+ <% for (let i = 0; i < it.modules.length; i++) { %>
39
+ <%
40
+ const { resourceName, pascalName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
41
+ %>
42
+ <% if(hasMiniAppWhitelistedApi) { %>
43
+ "<%= resourceName %>",
44
+ <% } %>
45
+ <% } %>
46
+ ];
@@ -0,0 +1,63 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2025-06-18
5
+ * Author: --
6
+ */
7
+
8
+ <%
9
+ const upperFirstCase = (value) => {
10
+ return value.charAt(0).toUpperCase() + value.slice(1);
11
+ }
12
+
13
+ const camelToKebab = (value) => {
14
+ return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
15
+ }
16
+
17
+ const getMiniAppInfo = (module) => {
18
+ const config = module.schema['x-simpleapp-config'];
19
+ const resourceName = config?.resourceName ?? config.documentName;
20
+
21
+ const pascalName = upperFirstCase(resourceName);
22
+ const kebabName = camelToKebab(resourceName);
23
+
24
+ const miniAppWhitelistApis = config?.miniApp?.whitelist || [];
25
+ const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
26
+
27
+ return {
28
+ resourceName,
29
+ pascalName,
30
+ kebabName,
31
+ hasMiniAppWhitelistedApi,
32
+ miniAppWhitelistApis,
33
+ }
34
+ }
35
+ %>
36
+
37
+ import { MiniAppResourceMap } from "../types/resource-mapper.type";
38
+ <% for (let i = 0; i < it.modules.length; i++) { %>
39
+ <%
40
+ const { pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
41
+ %>
42
+ <% if(hasMiniAppWhitelistedApi) { %>
43
+ import { MiniApp<%= pascalName %>BridgeService } from "../services/resources/<%= kebabName %>-bridge.service";
44
+ <% } %>
45
+ <% } %>
46
+
47
+ export class MiniAppBridgeResourceAccessor {
48
+ protected instances: Partial<MiniAppResourceMap> = {};
49
+
50
+ <% for (let i = 0; i < it.modules.length; i++) { %>
51
+ <%
52
+ const { resourceName, pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
53
+ %>
54
+ <% if(hasMiniAppWhitelistedApi) { %>
55
+ get <%= resourceName %>() {
56
+ if (!this.instances.<%= resourceName %>) {
57
+ this.instances.<%= resourceName %> = new MiniApp<%= pascalName %>BridgeService();
58
+ }
59
+ return this.instances.<%= resourceName %>;
60
+ }
61
+ <% } %>
62
+ <% } %>
63
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2025-06-18
5
+ * Author: --
6
+ */
7
+
8
+ import { SimpleAppDocumentType } from "~/types";
9
+ import {
10
+ MiniAppBridgeMessageApi,
11
+ MiniAppBridgeMessageNavigate,
12
+ MiniAppBridgeMessageOpenOnScreenResourceForm,
13
+ } from "../types/bridge.type";
14
+ import { AxiosError } from "axios";
15
+ import { MINI_APP_BRIDGE_MESSAGES } from "../constants/common.constant";
16
+ import { MiniAppResourceMap } from "../types/resource-mapper.type";
17
+ import { MiniAppBridgeResourceAccessor } from "./bridge-resource-accessor.service";
18
+ import { MINI_APP_API_RESOURCES } from "../constants/resource.constant";
19
+
20
+ export class MiniAppBridgeService extends MiniAppBridgeResourceAccessor {
21
+ /**************************************** Bridge Handler ***************************************/
22
+
23
+ handleBridgeNavigate(message: MiniAppBridgeMessageNavigate) {
24
+ goTo(message.params.target, message.params.id, message.params.query);
25
+ }
26
+
27
+ handleBridgeOpenOnScreenResourceForm(
28
+ message: MiniAppBridgeMessageOpenOnScreenResourceForm,
29
+ ) {
30
+ if (message.params.resource.id) {
31
+ onScreenEditDocument(
32
+ message.params.resource.name as SimpleAppDocumentType,
33
+ message.params.resource.id,
34
+ );
35
+ return;
36
+ }
37
+
38
+ onScreenAddDocument(message.params.resource.name as SimpleAppDocumentType, {
39
+ paras: message.params.data,
40
+ });
41
+ return;
42
+ }
43
+
44
+ async handleBridgeApi(
45
+ messageEvent: MessageEvent,
46
+ message: MiniAppBridgeMessageApi<any>,
47
+ ) {
48
+ try {
49
+ const data = await this.handleBridgeCallApi(message);
50
+
51
+ messageEvent.source?.postMessage(
52
+ {
53
+ type: MINI_APP_BRIDGE_MESSAGES.API_RESPONSE,
54
+ success: true,
55
+ requestId: message.requestId,
56
+ data,
57
+ },
58
+ {
59
+ targetOrigin: messageEvent.origin,
60
+ },
61
+ );
62
+ } catch (e) {
63
+ const err = e as AxiosError;
64
+
65
+ messageEvent.source?.postMessage(
66
+ {
67
+ type: MINI_APP_BRIDGE_MESSAGES.API_RESPONSE,
68
+ success: false,
69
+ requestId: message.requestId,
70
+ error: {
71
+ code: err.code,
72
+ message: err.message,
73
+ status: err.status,
74
+ response: err.response
75
+ ? {
76
+ data: err.response?.data
77
+ ? {
78
+ data: (err.response.data as any)?.data ?? "",
79
+ error: (err.response.data as any)?.error ?? "",
80
+ message: (err.response.data as any)?.message ?? "",
81
+ statusCode:
82
+ (err.response.data as any)?.statusCode ?? "",
83
+ statusMessage:
84
+ (err.response.data as any)?.statusMessage ?? "",
85
+ }
86
+ : {},
87
+ status: err.response.status,
88
+ statusText: err.response.statusText,
89
+ }
90
+ : {},
91
+ },
92
+ },
93
+ {
94
+ targetOrigin: messageEvent.origin,
95
+ },
96
+ );
97
+ }
98
+ }
99
+
100
+ private async handleBridgeCallApi(message: MiniAppBridgeMessageApi<any>) {
101
+ const resourceName = message.params.resource.name;
102
+
103
+ if (!MINI_APP_API_RESOURCES.includes(resourceName)) {
104
+ throw new Error(`Unknown resource name: ${resourceName}`);
105
+ }
106
+
107
+ const bridge = this[resourceName as keyof MiniAppResourceMap];
108
+ return await bridge.handleApi(message);
109
+ }
110
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2025-06-18
5
+ * Author: --
6
+ */
7
+
8
+ import { MINI_APP_BRIDGE_MESSAGES } from "../constants/common.constant";
9
+
10
+ export type MiniAppResource = {
11
+ name: string;
12
+ id?: string;
13
+ };
14
+
15
+ /************************************* Bridge Message Type *************************************/
16
+
17
+ export type MiniAppBridgeMessage<TAction> =
18
+ | MiniAppBridgeMessageNavigate
19
+ | MiniAppBridgeMessageOpenOnScreenResourceForm
20
+ | MiniAppBridgeMessageApi<TAction>
21
+ | MiniAppBridgeMessageInitResponse;
22
+
23
+ export type MiniAppBridgeMessageNavigate = {
24
+ type: typeof MINI_APP_BRIDGE_MESSAGES.NAVIGATE;
25
+ params: {
26
+ target: string;
27
+ id?: string;
28
+ query?: string;
29
+ };
30
+ };
31
+
32
+ export type MiniAppBridgeMessageOpenOnScreenResourceForm = {
33
+ type: typeof MINI_APP_BRIDGE_MESSAGES.OPEN_ON_SCREEN_RESOURCE_FORM;
34
+ params: {
35
+ resource: MiniAppResource;
36
+ data?: any;
37
+ };
38
+ };
39
+
40
+ export type MiniAppBridgeMessageApi<TActions> = {
41
+ type: typeof MINI_APP_BRIDGE_MESSAGES.API;
42
+ requestId: string;
43
+ params: {
44
+ action: TActions;
45
+ resource: MiniAppResource;
46
+ /**
47
+ * For auto complete filter
48
+ */
49
+ query?: string;
50
+ /**
51
+ * For :id/:code/xxx
52
+ */
53
+ queryParams?: {
54
+ [key: string]: any;
55
+ };
56
+ body?: {
57
+ [key: string]: any;
58
+ };
59
+ };
60
+ };
61
+
62
+ export type MiniAppBridgeMessageApiResponse<TData> = {
63
+ type: typeof MINI_APP_BRIDGE_MESSAGES.API_RESPONSE;
64
+ requestId: string;
65
+ success: boolean;
66
+ data?: TData;
67
+ error?: any;
68
+ };
69
+
70
+ export type MiniAppBridgeMessageInitResponse = {
71
+ type: typeof MINI_APP_BRIDGE_MESSAGES.INIT_RESPONSE;
72
+ };