@fernir2/saas-kit-cli 0.1.25 → 0.1.27

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 (81) hide show
  1. package/base-repo/app-constants/aliases.cjs.js +1 -1
  2. package/base-repo/app-constants/aliases.js +1 -1
  3. package/cli/.gitlab-ci.yml +15 -0
  4. package/cli/.husky/commit-msg +1 -0
  5. package/cli/.husky/pre-commit +1 -0
  6. package/cli/README.md +336 -56
  7. package/cli/bin/index.ts +1 -1
  8. package/cli/postcss.config.mjs +0 -1
  9. package/cli/server.ts +41 -0
  10. package/cli/tsconfig.declaration.json +48 -0
  11. package/level2/cli/create-saas-kit-app/bin/index.cjs.js +4 -4
  12. package/level2/cli/create-saas-kit-app/bin/index.js +3 -3
  13. package/level2/fd-toolbox/api/api-client.cjs.js +1 -1
  14. package/level2/fd-toolbox/api/api-client.js +1 -1
  15. package/level2/fd-toolbox/api/api-path-names.cjs.js +2 -2
  16. package/level2/fd-toolbox/api/api-paths.cjs.js +1 -1
  17. package/level2/fd-toolbox/api/api-paths.js +1 -1
  18. package/level2/fd-toolbox/api/base-api.cjs.js +1 -1
  19. package/level2/fd-toolbox/api/base-api.js +1 -1
  20. package/level2/fd-toolbox/auth/login-states.cjs.js +1 -1
  21. package/level2/fd-toolbox/auth/login-states.js +1 -1
  22. package/level2/fd-toolbox/auth/session-storage.cjs.js +1 -1
  23. package/level2/fd-toolbox/auth/session-storage.js +1 -1
  24. package/level2/fd-toolbox/auth/tokens.cjs.js +1 -1
  25. package/level2/fd-toolbox/auth/tokens.js +1 -1
  26. package/level2/fd-toolbox/constants/constants.cjs.js +1 -1
  27. package/level2/fd-toolbox/constants/constants.js +1 -1
  28. package/level2/fd-toolbox/enums/enums.cjs.js +1 -1
  29. package/level2/fd-toolbox/enums/enums.js +1 -1
  30. package/level2/fd-toolbox/errors/error-handler.cjs.js +1 -1
  31. package/level2/fd-toolbox/errors/error-handler.js +1 -1
  32. package/level2/fd-toolbox/errors/errors.cjs.js +1 -1
  33. package/level2/fd-toolbox/errors/errors.js +1 -1
  34. package/level2/fd-toolbox/errors/problem-details.cjs.js +1 -1
  35. package/level2/fd-toolbox/errors/problem-details.js +1 -1
  36. package/level2/fd-toolbox/functions/value-checking-functions.cjs.js +1 -1
  37. package/level2/fd-toolbox/functions/value-checking-functions.js +1 -1
  38. package/level2/fd-toolbox/http/url/urls.cjs.js +1 -1
  39. package/level2/fd-toolbox/http/url/urls.js +1 -1
  40. package/level2/fd-toolbox/infra/env-config.cjs.js +2 -2
  41. package/level2/fd-toolbox/infra/env-config.js +2 -2
  42. package/level2/fd-toolbox/infra/env-functions.cjs.js +1 -1
  43. package/level2/fd-toolbox/infra/env-functions.js +1 -1
  44. package/level2/fd-toolbox/infra/env-schema.cjs.js +2 -2
  45. package/level2/fd-toolbox/infra/env-schema.js +2 -2
  46. package/level2/fd-toolbox/infra/env-store.cjs.js +1 -1
  47. package/level2/fd-toolbox/infra/env-store.js +1 -1
  48. package/level2/fd-toolbox/lib/environments.cjs.js +1 -1
  49. package/level2/fd-toolbox/lib/environments.js +1 -1
  50. package/level2/fd-toolbox/lib/utils.cjs.js +1 -1
  51. package/level2/fd-toolbox/lib/utils.js +1 -1
  52. package/level2/fd-toolbox/local-storage/local-storage.cjs.js +1 -1
  53. package/level2/fd-toolbox/local-storage/local-storage.js +1 -1
  54. package/level2/fd-toolbox/logging/loggers.cjs.js +1 -1
  55. package/level2/fd-toolbox/logging/loggers.js +1 -1
  56. package/level2/fd-toolbox/notifications.cjs.js +2 -2
  57. package/level2/fd-toolbox/notifications.js +2 -2
  58. package/level2/fd-toolbox/odata/odata-constants.cjs.js +1 -1
  59. package/level2/fd-toolbox/odata/odata-constants.js +1 -1
  60. package/level2/fd-toolbox/odata/odatas.cjs.js +1 -1
  61. package/level2/fd-toolbox/odata/odatas.js +1 -1
  62. package/level2/fd-toolbox/odata/services/odata-filters.cjs.js +1 -1
  63. package/level2/fd-toolbox/odata/services/odata-filters.js +1 -1
  64. package/level2/fd-toolbox/paths/paths-names.cjs.js +2 -2
  65. package/level2/fd-toolbox/paths/paths-names.js +1 -1
  66. package/level2/fd-toolbox/routing/login-routers.cjs.js +1 -1
  67. package/level2/fd-toolbox/routing/login-routers.js +1 -1
  68. package/level2/fd-toolbox/routing/paths.cjs.js +1 -1
  69. package/level2/fd-toolbox/routing/paths.js +1 -1
  70. package/level2/fd-toolbox/strings/strings-constants.cjs.js +1 -1
  71. package/level2/fd-toolbox/strings/strings-constants.js +1 -1
  72. package/level2/fd-toolbox/strings/strings.cjs.js +1 -1
  73. package/level2/fd-toolbox/strings/strings.js +1 -1
  74. package/level2/fd-toolbox/types/ensure-type.cjs.js +1 -1
  75. package/level2/fd-toolbox/types/ensure-type.js +1 -1
  76. package/level2/fd-toolbox-core/core/name-of.cjs.js +1 -1
  77. package/level2/fd-toolbox-core/core/name-of.js +1 -1
  78. package/level2/fd-toolbox-core/types/resource-with-id.cjs.js +1 -1
  79. package/level2/fd-toolbox-core/types/resource-with-id.js +1 -1
  80. package/package.json +1 -1
  81. package/cli/.env +0 -55
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
  'use strict';
3
3
 
4
- const aliasSymbols={'atSign':'@','rootAlias':'@root/'};const typescriptAliases={'@':'./src','@cli':'./packages/level2/cli','@server':'./packages/level2/server','@schemas':'./generated','@npm-commands':'./packages/level2/npm-commands','@root':'.','@enricher':'./packages/level2/enricher','@packages':'./packages','@common':'./packages/level2/common','@meta':'./packages/level2/meta','@fd-toolbox':'./packages/level2/fd-toolbox','@fd-toolbox-core':'./packages/level2/fd-toolbox-core','@fd-component-toolbox':'./packages/level2/fd-component-toolbox','@fd-app-toolbox':'./packages/level2/fd-app-toolbox','@client':'./packages/level2/client'};const modulePathAliases=Object['fromEntries'](Object['entries'](typescriptAliases)['map'](([_0x16259a,_0x1030f6])=>[_0x16259a+'/*',[_0x1030f6+'/*']]));
4
+ const aliasSymbols={'atSign':'@','rootAlias':'@root/'};const typescriptAliases={'@':'./src','@cli':'./packages/level2/cli','@server':'./packages/level2/server','@schemas':'./generated','@npm-commands':'./packages/level2/npm-commands','@root':'.','@enricher':'./packages/level2/enricher','@packages':'./packages','@common':'./packages/level2/common','@meta':'./packages/level2/meta','@fd-toolbox':'./packages/level2/fd-toolbox','@fd-toolbox-core':'./packages/level2/fd-toolbox-core','@fd-component-toolbox':'./packages/level2/fd-component-toolbox','@fd-app-toolbox':'./packages/level2/fd-app-toolbox','@client':'./packages/level2/client'};const modulePathAliases=Object['fromEntries'](Object['entries'](typescriptAliases)['map'](([_0x3c464e,_0x126176])=>[_0x3c464e+'/*',[_0x126176+'/*']]));
5
5
 
6
6
  exports.aliasSymbols = aliasSymbols;
7
7
  exports.modulePathAliases = modulePathAliases;
@@ -1,4 +1,4 @@
1
1
  'use strict';
2
- const aliasSymbols={'atSign':'@','rootAlias':'@root/'};const typescriptAliases={'@':'./src','@cli':'./packages/level2/cli','@server':'./packages/level2/server','@schemas':'./generated','@npm-commands':'./packages/level2/npm-commands','@root':'.','@enricher':'./packages/level2/enricher','@packages':'./packages','@common':'./packages/level2/common','@meta':'./packages/level2/meta','@fd-toolbox':'./packages/level2/fd-toolbox','@fd-toolbox-core':'./packages/level2/fd-toolbox-core','@fd-component-toolbox':'./packages/level2/fd-component-toolbox','@fd-app-toolbox':'./packages/level2/fd-app-toolbox','@client':'./packages/level2/client'};const modulePathAliases=Object['fromEntries'](Object['entries'](typescriptAliases)['map'](([_0x16259a,_0x1030f6])=>[_0x16259a+'/*',[_0x1030f6+'/*']]));
2
+ const aliasSymbols={'atSign':'@','rootAlias':'@root/'};const typescriptAliases={'@':'./src','@cli':'./packages/level2/cli','@server':'./packages/level2/server','@schemas':'./generated','@npm-commands':'./packages/level2/npm-commands','@root':'.','@enricher':'./packages/level2/enricher','@packages':'./packages','@common':'./packages/level2/common','@meta':'./packages/level2/meta','@fd-toolbox':'./packages/level2/fd-toolbox','@fd-toolbox-core':'./packages/level2/fd-toolbox-core','@fd-component-toolbox':'./packages/level2/fd-component-toolbox','@fd-app-toolbox':'./packages/level2/fd-app-toolbox','@client':'./packages/level2/client'};const modulePathAliases=Object['fromEntries'](Object['entries'](typescriptAliases)['map'](([_0x3c464e,_0x126176])=>[_0x3c464e+'/*',[_0x126176+'/*']]));
3
3
 
4
4
  export { aliasSymbols, modulePathAliases, typescriptAliases };
@@ -0,0 +1,15 @@
1
+ include:
2
+ - "packages/infra/ci/templates/ci-variables.yml"
3
+ - "packages/infra/ci/templates/base-template.yml"
4
+
5
+ - "packages/infra/ci/templates/build-package.yml"
6
+ - "packages/infra/ci/templates/lint.yml"
7
+ - "packages/infra/ci/templates/build-and-test.yml"
8
+ - "packages/infra/ci/templates/saas-kit-test-build-and-test.yml"
9
+ - "packages/infra/ci/templates/create-saas-kit-app-test.yml"
10
+
11
+ - "packages/infra/ci/templates/manual-cleanup.yml"
12
+ - "packages/infra/ci/templates/update-submodules.yml"
13
+ - "packages/infra/ci/templates/deploy-to-vercel.yml"
14
+ - "packages/infra/ci/templates/clear-nx-cache.yml"
15
+ - "packages/infra/ci/templates/drop-all-db.yml"
@@ -0,0 +1 @@
1
+ npx tsx packages/base-repo/tools/git/commit-msg-script.ts "$1"
@@ -0,0 +1 @@
1
+ pnpm run-precommit
package/cli/README.md CHANGED
@@ -1,101 +1,381 @@
1
- ## Getting started
1
+ # Getting Started
2
2
 
3
- To make it easy for you to get started with GitLab, here's a list of recommended next steps.
3
+ :::warning[Important Notice]
4
+ Our project documentation is still in development. We have a public release scheduled for September 2025, and the
5
+ documentation will be more complete by then. Please note that the current documentation is not final and more
6
+ information will be added over time.
7
+ :::
4
8
 
5
- Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
9
+ This tutorial assumes you are using Bash or Git Bash.
10
+ Run in the terminal:
6
11
 
7
- ## Add your files
12
+ ```bash
13
+ npx create-saas-kit-app
14
+ ```
15
+
16
+ Find in the root folder file `.env.example`. Copy it and rename to the `.env` file. In this file replace the value of `DATABASE_CONNECTION_STRING` with a suitable one.
17
+
18
+ Then run:
19
+
20
+ ```bash
21
+ npm install
22
+ # Create tutorial folder
23
+ mkdir -p src/app/tutorial
24
+ # Create file
25
+ touch src/app/tutorial/student.resource.ts
26
+ ```
27
+
28
+ In SaaS Kit everything revolves around resources. Resource is an entity in your system, it can be a database
29
+ table or api endpoint or business object. `Order`, `Contact`, `Address` or `User` can be examples of resources.
30
+ They are called resources because of Uniform Resource Locator (Url).
31
+
32
+ Let's create Student resource, add the following code inside `student.resource.ts` file:
33
+
34
+ ```ts
35
+ @resourceMetaId("d4507481-8b33-46e7-9c2e-606daab170cc")
36
+ export class Student extends WorkspaceResource {
37
+ name!: string;
38
+ }
39
+ ```
40
+
41
+ Resolve import for @[resourceId](/docs/src/functions/resourceId) so you don't have red squiggly lines. Going forward we will assume that you
42
+ are going to resolve imports by yourself.
43
+
44
+ Resource files must end with `.resource.ts` extension and they need to have @[resourceId](/docs/src/functions/resourceId) decorator with
45
+ randomly generated Uuid. Let's start the app:
46
+
47
+ ```bash
48
+ npm start
49
+ ```
50
+
51
+ In the future you can choose which command will be used for starting the application:
52
+
53
+ ```bash
54
+ npm start
55
+ ```
56
+
57
+ or
58
+
59
+ ```bash
60
+ npm run dev
61
+ ```
62
+
63
+ `start` will generate metadata files and seed database every time, and `dev` skips of that and is much faster.
64
+
65
+ After starting the application, verify that the resource was properly created in your PostgreSQL database:
66
+
67
+ 1. Connect to your PostgreSQL database using your preferred client (psql, pgAdmin, etc.)
68
+ 2. Check that the `student` table was created automatically
69
+ 3. Verify the table structure has `name` column
70
+
71
+ Once the database setup is verified, open it in the browser. Click `Sign In`.
72
+ Then go to `/view?resource=Student` page to see Student resource.
73
+ Click on `+` button to add a Student. Fill in all nessesary fields and click `Save` button.
74
+
75
+ ### Adding resources to Sidebar
76
+
77
+ To have easier access to resource you can add it to Sidebar.
78
+
79
+ To add Student to Sidebar go to `layout.tsx` where you will find `ClientRoot` component
80
+ and add to the component's `sideBarResources` prop
81
+ with `Student` in it:
82
+
83
+ ```tsx
84
+ <ClientRoot sideBarResources={["Student"]}>{children}</ClientRoot>
85
+ ```
86
+
87
+ ### Resource relations
88
+
89
+ Saas-kit automatically understands relations between resources. For this you just need to follow our code conventions.
90
+ For example:
91
+
92
+ 1. Create Teacher resource that you want to connect to Student resource:
93
+
94
+ ```ts
95
+ @resourceMetaId("783cbb56-0ee2-4d78-b7f1-2e139c8738d3")
96
+ export class Teacher extends WorkspaceResource {
97
+ name!: string;
98
+ }
99
+ ```
100
+
101
+ 2. Add links to each other to create relation between Student and Teacher resources.
102
+ For an one-to-many relation you need to add a `{resource}Id` field to first resource
103
+ and a `{resource}List` field to second resource:
104
+
105
+ ```ts
106
+ export class Student extends WorkspaceResource {
107
+ name!: string;
108
+
109
+ teacherId?: string;
110
+
111
+ teacher?: Teacher;
112
+ }
113
+
114
+ export class Teacher extends WorkspaceResource {
115
+ name!: string;
116
+
117
+ studentList?: Student[];
118
+ }
119
+ ```
120
+
121
+ 3. Use `npm start` command to create the relation.
122
+
123
+ Now, going to `view?resource=Student` and looking upwards there appears new filter `Teacher`.
124
+ You can click on it and choose a Teacher to filter Students by.
125
+ If you want to add Teacher column to Student [ResourceList](/docs/src/functions/ResourceList), you can add decorator @[expandDescription](/docs/src/functions/expandDescription) to Student resource:
8
126
 
9
- - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
10
- - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
127
+ ```ts
128
+ export class Student extends WorkspaceResource {
129
+ name!: string;
11
130
 
131
+ @expandDescription()
132
+ teacherId?: string;
133
+ teacher?: Teacher;
134
+ }
12
135
  ```
13
- cd existing_repo
14
- git remote add origin https://gitlab.com/flexdev/gitlab-spokbee-saas.git
15
- git branch -M main
16
- git push -uf origin main
136
+
137
+ ## Getting resources on frontend
138
+
139
+ Use [`fetchResource()`](/docs/src/functions/fetchResource) when you need to fetch a single resource.
140
+
141
+ ```ts
142
+ const student = await fetchResource<Student>("Student", studentId);
143
+ ```
144
+
145
+ Use [`fetchResources()`](/docs/src/functions/fetchResources) when you need to fetch a list of resources.
146
+
147
+ ```ts
148
+ const students = await fetchResources<Student>("Student");
149
+ ```
150
+
151
+ ## Getting resources on backend
152
+
153
+ Function [getResourcesByName](/docs/packages/server/fd/fd-toolbox/db/db/functions/getResourcesByName) gets resources by name from database.
154
+ For Student resource function returns array of Student:
155
+
156
+ ```ts
157
+ const students = await getResourcesByName<Student>("Student");
158
+ ```
159
+
160
+ Function getResourceById gets a resource by its id and resourceName.
161
+ Function throws an error if resource isn't found.
162
+ If you want to skip the error add `false` as a third parameter:
163
+
164
+ ```ts
165
+ const students = await getResourceById<Student>("Student", studentId, false);
166
+ ```
167
+
168
+ ## Configure search
169
+
170
+ To enable search functionality for a resource based on specific fields, use the [searchable](packages/docs/content/src/functions/searchable.md) decorator on the properties you want to make searchable.
171
+ You can mark multiple fields within a single resource as searchable.
172
+
173
+ ```ts
174
+ class Student {
175
+ @searchable()
176
+ name: string;
177
+ }
178
+ ```
179
+
180
+ When the `name` field is marked as searchable, users will be able to find a student by typing their name into the search bar at the top-left corner of the page.
181
+
182
+ ## Create role with permission
183
+
184
+ First we create the permission via [configurePermission](/docs/packages/server/functions/configurePermission)
185
+
186
+ ```ts
187
+ const studentPermisionId = getNewUuid();
188
+ await configurePermission(studentPermisionId, "EditStudent");
17
189
  ```
18
190
 
19
- ## Integrate with your tools
191
+ Then we create the role via [upsertRole](/docs/packages/server/functions/upsertRole)
20
192
 
21
- - [ ] [Set up project integrations](https://gitlab.com/flexdev/gitlab-spokbee-saas/-/settings/integrations)
193
+ ```ts
194
+ const studentRoleId = getNewUuid();
195
+ const role: Role = {
196
+ id: studentRoleId,
197
+ name: "ClassPresident",
198
+ level: permissionLevels.ten,
199
+ };
200
+ await upsertRole(role);
201
+ ```
22
202
 
23
- ## Collaborate with your team
203
+ Next we use the function [createRoleToPermissionIfNotExist](/docs/packages/server/functions/createRoleToPermissionIfNotExist)
24
204
 
25
- - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
26
- - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
27
- - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
28
- - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
29
- - [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
205
+ ```ts
206
+ await createRoleToPermissionIfNotExist(role.id, [
207
+ studentPermisionId,
208
+ ]);
209
+ ```
30
210
 
31
- ## Test and Deploy
211
+ ## Most common decorators
212
+
213
+ Here are the top 5 most commonly used decorators — check out the documentation to learn more about them:
214
+
215
+ - [expandDescription](docs/src/functions/expandDescription)
216
+ - [accessByUserId](docs/src/functions/accessByUserId)
217
+ - [descriptionProperty](docs/src/functions/descriptionProperty)
218
+ - [notDisplayable](docs/src/functions/notDisplayable)
219
+ - [icon](docs/src/functions/icon)
220
+
221
+ ## Seeding data
222
+
223
+ If you want to add additional data that is seeded on the app start you can open file `npm-commands/seed-db/index.ts`. In it, using function [crudCreate](/docs/packages/server/meta/fd-meta/basic-crud/cruds/functions/crudCreate) you can add any resources into your database.
224
+ Function [crudCreate](/docs/packages/server/meta/fd-meta/basic-crud/cruds/functions/crudCreate) accepts [CrudUpdateConfig](docs/packages/server/interfaces/CrudUpdateConfig) parameter and creates a resource.
225
+
226
+ ```ts
227
+ async function seed() {
228
+ try {
229
+ await seedDataBase();
230
+ await createTeacher();
231
+ await createStudent();
232
+ logInfo("Database seeded succesfully");
233
+ process.exit(0);
234
+ } catch (err) {
235
+ if (err instanceof Error) console.log("Error seeding database", err);
236
+
237
+ process.exit(1);
238
+ }
239
+ }
240
+
241
+ async function createStudent() {
242
+ const studentConfig: CrudUpdateConfig<Student> = {
243
+ resourceName: "Student",
244
+ resource: studentData,
245
+ };
246
+ await crudCreate<Student>(studentConfig);
247
+ }
248
+
249
+ async function createTeacher() {
250
+ const teacherConfig: CrudUpdateConfig<Teacher> = {
251
+ resourceName: "Teacher",
252
+ resource: teacherData,
253
+ };
254
+ await crudCreate<Teacher>(teacherConfig);
255
+ }
256
+ ```
32
257
 
33
- Use the built-in continuous integration in GitLab.
258
+ If you want to seed demo resources that are displayed in this [video](https://youtu.be/RrHFmirV0j0) (for example `Contact`, `Company`, `Ticket`), add to the `.env` file:
34
259
 
35
- - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
36
- - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
37
- - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
38
- - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
39
- - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
260
+ `NEXT_PUBLIC_FD_SEED_DEMO_RESOURCES = true`
40
261
 
41
- ---
262
+ ## Checking for permissions
42
263
 
43
- # Editing this README
264
+ #### On frontend
44
265
 
45
- When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
266
+ [checkAndNotifyCrudPermission](docs/src/functions/checkAndNotifyCrudPermission) checks only explicit permissions and shows a notification if the user does not have access.
267
+ The first argument specifies which CRUD action you want to verify.
46
268
 
47
- ## Suggestions for a good README
269
+ ```ts
270
+ checkAndNotifyCrudPermission(crudActions.create, uiMeta.resourceMeta, studentData);
271
+ ```
48
272
 
49
- Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
273
+ In some cases you might want to use a less resctrictive permission checker. For that, examine [checkAndNotifyCrudPermissionLessResctrictive](docs/src/functions/checkAndNotifyCrudPermissionLessResctrictive) function
50
274
 
51
- ## Name
275
+ #### On backend
52
276
 
53
- Choose a self-explaining name for your project.
277
+ [getPermissionCheckConfig](docs/src/functions/getPermissionCheckConfig) — creates a configuration object for a specific user, resource metadata, and resource data.
278
+ [hasPermissionByPermissionCheckConfig](docs/src/functions/hasPermissionByPermissionCheckConfig) — checks permissions based on a prepared config.
54
279
 
55
- ## Description
280
+ ```ts
281
+ const permissionConfig = getPermissionCheckConfig(userId, studentMeta, studentData);
282
+ const hasPermission = await hasPermissionByPermissionCheckConfig(permissionConfig);
283
+ console.log(hasPermission) //false
284
+ ```
56
285
 
57
- Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
286
+ [hasPermissionByUserId](docs/src/functions/hasPermissionByUserId) checks whether a user has permission to perform a given CRUD action on a resource.
58
287
 
59
- ## Badges
288
+ ```ts
289
+ const hasPermission = await hasPermissionByUserId("Student", crudActions.create, userId);
290
+ console.log(hasPermission) //false
291
+ ```
292
+
293
+ #### Add custom permission checks
60
294
 
61
- On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
295
+ If you want to perform custom permission check you can use add [@permissionCheckerFor](docs/src/functions/permissionCheckerFor) decorator.
62
296
 
63
- ## Visuals
297
+ ```ts
298
+ const customChecker: ResourcePermissionChecker = async (
299
+ studentData,
300
+ userId,
301
+ crudActions.create
302
+ ) => {
303
+ return userId === userIds.timWId;
304
+ };
64
305
 
65
- Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
306
+ @permissionCheckerFor("Student", customChecker)
307
+ @resourceId("d4507481-8b33-46e7-9c2e-606daab170cc")
308
+ export class Student extends WorkspaceResource {...}
309
+ ```
66
310
 
67
- ## Installation
311
+ In this example only user timW will be able to modify this resource.
68
312
 
69
- Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
313
+ ## Send notifications
70
314
 
71
- ## Usage
315
+ [sendNotification](packages/docs/content/src/functions/sendNotification) - sends a notification to a user and stores it in the database.
316
+
317
+ ```ts
318
+ await sendNotification(
319
+ studentUserId,
320
+ "New feature available",
321
+ "Check out the new feature in your dashboard"
322
+ );
323
+ ```
72
324
 
73
- Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
325
+ It will look like this:
74
326
 
75
- ## Support
327
+ ![notification ui](packages/docs/screenshots/notification-example.png)
76
328
 
77
- Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
329
+ #### Sending emails
78
330
 
79
- ## Roadmap
331
+ If you also want the notification to be sent by email, specify:
332
+
333
+ - `isExternal = true`
334
+ - `FD_SEND_EMAIL = true` in `.env`
335
+ - register with _SendGrid_ to get and configure `FD_EMAIL_SERVICE_URL` and `FD_SERVICE_KEY` in `.env`
336
+
337
+ ```ts
338
+ await sendNotification(
339
+ studentUserId,
340
+ "New feature available",
341
+ "Check out the new feature in your dashboard",
342
+ true
343
+ );
344
+ ```
345
+
346
+ Functions for showing simple toast UI notifications:
347
+
348
+ ```ts
349
+ notify("Notify message");
350
+ ```
351
+
352
+ ```ts
353
+ notifySuccess("Notify success message");
354
+ ```
355
+
356
+ ```ts
357
+ notifyFailure("Notify failure message");
358
+ ```
80
359
 
81
- If you have ideas for releases in the future, it is a good idea to list them in the README.
360
+ It will look like this:
361
+ ![toaster ui](packages/docs/screenshots/toaster-notify-succes.png)
82
362
 
83
- ## Contributing
363
+ ## Add role to a user
84
364
 
85
- State if you are open to contributions and what your requirements are for accepting them.
365
+ To assign a new role to a user, open `UserRole` menu and click `+` button.
86
366
 
87
- For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
367
+ ![alt text](packages/docs/screenshots/open-add-role-menu.png)
88
368
 
89
- You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
369
+ In the `User` field, select the user you want to assign a role to. Then, in the `Role` field, choose the role you want to give. Finally click `Save` to apply the changes.
90
370
 
91
- ## Authors and acknowledgment
371
+ ![alt text](packages/docs/screenshots/role-menu.png)
92
372
 
93
- Show your appreciation to those who have contributed to the project.
373
+ ## Assign role to permission
94
374
 
95
- ## License
375
+ To assign permissions to a role, open the RoleToPermission menu and click the `+` button.
96
376
 
97
- For open source projects, say how it is licensed.
377
+ ![alt text](packages/docs/screenshots/open-role-to-permission-menu.png)
98
378
 
99
- ## Project status
379
+ In the `Role` field, select the role you want to assign. Then, in the `Permission` field, choose the permission you want to give. Finally, click `Save` to confirm.
100
380
 
101
- If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
381
+ ![alt text](packages/docs/screenshots/role-to-permission-menu.png)
package/cli/bin/index.ts CHANGED
@@ -298,7 +298,7 @@ async function main() {
298
298
  process.exit(1);
299
299
  }
300
300
 
301
- const folderName: string = args[0];
301
+ const folderName: string = args[1];
302
302
  const targetDir: string = path.resolve(process.cwd(), folderName);
303
303
 
304
304
  logInfoRaw(`\nCreating ${projectName} project "${folderName}"...\n`);
@@ -2,7 +2,6 @@
2
2
  const config = {
3
3
  plugins: {
4
4
  tailwindcss: {},
5
- autoprefixer: {},
6
5
  },
7
6
  };
8
7
 
package/cli/server.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { createServer } from "node:http";
2
+ import { parse } from "url";
3
+ import next from "next";
4
+ import {
5
+ checkAndHandleWebSocketRequest,
6
+ initSocket,
7
+ initializeInternalMetaCache,
8
+ } from "@fernir2/saas-kit/server";
9
+ import { envSettingKeys, getNumberEnvSetting, isDev } from "@fernir2/saas-kit";
10
+
11
+ const dev = isDev();
12
+ const port = getNumberEnvSetting(envSettingKeys.fdPort) ?? 3000;
13
+
14
+ const app = next({ dev, port });
15
+ const nextRequestHandler = app.getRequestHandler();
16
+
17
+ async function run() {
18
+ await app.prepare();
19
+
20
+ const httpServer = createServer((req, res) => {
21
+ checkAndHandleWebSocketRequest(req, res);
22
+
23
+ const parsedUrl = parse(req.url!, true);
24
+ nextRequestHandler(req, res, parsedUrl);
25
+ });
26
+
27
+ initSocket(httpServer);
28
+
29
+ httpServer
30
+ .once("error", (err) => {
31
+ console.error(err);
32
+ process.exit(1);
33
+ })
34
+ .listen(port, () => {
35
+ console.log(`> Ready on http://localhost:${port}`);
36
+ });
37
+
38
+ await initializeInternalMetaCache();
39
+ }
40
+
41
+ run();
@@ -0,0 +1,48 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "experimentalDecorators": true,
5
+ "emitDecoratorMetadata": true,
6
+ "lib": ["dom", "dom.iterable", "esnext"],
7
+ "allowJs": true,
8
+ "skipLibCheck": true,
9
+ "strict": false,
10
+ "esModuleInterop": true,
11
+ "module": "esnext",
12
+ "moduleResolution": "bundler",
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": false,
15
+ "jsx": "preserve",
16
+ "incremental": false,
17
+ "plugins": [
18
+ {
19
+ "name": "next"
20
+ }
21
+ ],
22
+ "paths": {
23
+ "@/*": ["./src/*"],
24
+ "@cli/*": ["./packages/level2/cli/*"],
25
+ "@server/*": ["./packages/level2/server/*"],
26
+ "@schemas/*": ["./generated/*"],
27
+ "@npm-commands/*": ["./packages/level2/npm-commands/*"],
28
+ "@root/*": ["./*"],
29
+ "@enricher/*": ["./packages/level2/enricher/*"],
30
+ "@packages/*": ["./packages/*"],
31
+ "@common/*": ["./packages/level2/common/*"],
32
+ "@fd-app-toolbox/*": ["./packages/level2/fd-app-toolbox/*"],
33
+ "@fd-component-toolbox/*": ["./packages/level2/fd-component-toolbox/*"],
34
+ "@fd-toolbox-core/*": ["./packages/level2/fd-toolbox-core/*"],
35
+ "@fd-toolbox/*": ["./packages/level2/fd-toolbox/*"],
36
+ "@meta/*": ["./packages/level2/meta/*"],
37
+ "@base-repo/*": ["./packages/base-repo/*"],
38
+ "@client/*": ["./packages/level2/client/*"]
39
+ },
40
+ "outDir": "./build/package",
41
+ "rootDir": "./",
42
+ "declaration": true,
43
+ "declarationDir": "./build/package",
44
+ "emitDeclarationOnly": false
45
+ },
46
+ "include": ["next-env.d.ts", "lib/**/*.ts"],
47
+ "exclude": ["node_modules", "dist"]
48
+ }