@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.
- package/base-repo/app-constants/aliases.cjs.js +1 -1
- package/base-repo/app-constants/aliases.js +1 -1
- package/cli/.gitlab-ci.yml +15 -0
- package/cli/.husky/commit-msg +1 -0
- package/cli/.husky/pre-commit +1 -0
- package/cli/README.md +336 -56
- package/cli/bin/index.ts +1 -1
- package/cli/postcss.config.mjs +0 -1
- package/cli/server.ts +41 -0
- package/cli/tsconfig.declaration.json +48 -0
- package/level2/cli/create-saas-kit-app/bin/index.cjs.js +4 -4
- package/level2/cli/create-saas-kit-app/bin/index.js +3 -3
- package/level2/fd-toolbox/api/api-client.cjs.js +1 -1
- package/level2/fd-toolbox/api/api-client.js +1 -1
- package/level2/fd-toolbox/api/api-path-names.cjs.js +2 -2
- package/level2/fd-toolbox/api/api-paths.cjs.js +1 -1
- package/level2/fd-toolbox/api/api-paths.js +1 -1
- package/level2/fd-toolbox/api/base-api.cjs.js +1 -1
- package/level2/fd-toolbox/api/base-api.js +1 -1
- package/level2/fd-toolbox/auth/login-states.cjs.js +1 -1
- package/level2/fd-toolbox/auth/login-states.js +1 -1
- package/level2/fd-toolbox/auth/session-storage.cjs.js +1 -1
- package/level2/fd-toolbox/auth/session-storage.js +1 -1
- package/level2/fd-toolbox/auth/tokens.cjs.js +1 -1
- package/level2/fd-toolbox/auth/tokens.js +1 -1
- package/level2/fd-toolbox/constants/constants.cjs.js +1 -1
- package/level2/fd-toolbox/constants/constants.js +1 -1
- package/level2/fd-toolbox/enums/enums.cjs.js +1 -1
- package/level2/fd-toolbox/enums/enums.js +1 -1
- package/level2/fd-toolbox/errors/error-handler.cjs.js +1 -1
- package/level2/fd-toolbox/errors/error-handler.js +1 -1
- package/level2/fd-toolbox/errors/errors.cjs.js +1 -1
- package/level2/fd-toolbox/errors/errors.js +1 -1
- package/level2/fd-toolbox/errors/problem-details.cjs.js +1 -1
- package/level2/fd-toolbox/errors/problem-details.js +1 -1
- package/level2/fd-toolbox/functions/value-checking-functions.cjs.js +1 -1
- package/level2/fd-toolbox/functions/value-checking-functions.js +1 -1
- package/level2/fd-toolbox/http/url/urls.cjs.js +1 -1
- package/level2/fd-toolbox/http/url/urls.js +1 -1
- package/level2/fd-toolbox/infra/env-config.cjs.js +2 -2
- package/level2/fd-toolbox/infra/env-config.js +2 -2
- package/level2/fd-toolbox/infra/env-functions.cjs.js +1 -1
- package/level2/fd-toolbox/infra/env-functions.js +1 -1
- package/level2/fd-toolbox/infra/env-schema.cjs.js +2 -2
- package/level2/fd-toolbox/infra/env-schema.js +2 -2
- package/level2/fd-toolbox/infra/env-store.cjs.js +1 -1
- package/level2/fd-toolbox/infra/env-store.js +1 -1
- package/level2/fd-toolbox/lib/environments.cjs.js +1 -1
- package/level2/fd-toolbox/lib/environments.js +1 -1
- package/level2/fd-toolbox/lib/utils.cjs.js +1 -1
- package/level2/fd-toolbox/lib/utils.js +1 -1
- package/level2/fd-toolbox/local-storage/local-storage.cjs.js +1 -1
- package/level2/fd-toolbox/local-storage/local-storage.js +1 -1
- package/level2/fd-toolbox/logging/loggers.cjs.js +1 -1
- package/level2/fd-toolbox/logging/loggers.js +1 -1
- package/level2/fd-toolbox/notifications.cjs.js +2 -2
- package/level2/fd-toolbox/notifications.js +2 -2
- package/level2/fd-toolbox/odata/odata-constants.cjs.js +1 -1
- package/level2/fd-toolbox/odata/odata-constants.js +1 -1
- package/level2/fd-toolbox/odata/odatas.cjs.js +1 -1
- package/level2/fd-toolbox/odata/odatas.js +1 -1
- package/level2/fd-toolbox/odata/services/odata-filters.cjs.js +1 -1
- package/level2/fd-toolbox/odata/services/odata-filters.js +1 -1
- package/level2/fd-toolbox/paths/paths-names.cjs.js +2 -2
- package/level2/fd-toolbox/paths/paths-names.js +1 -1
- package/level2/fd-toolbox/routing/login-routers.cjs.js +1 -1
- package/level2/fd-toolbox/routing/login-routers.js +1 -1
- package/level2/fd-toolbox/routing/paths.cjs.js +1 -1
- package/level2/fd-toolbox/routing/paths.js +1 -1
- package/level2/fd-toolbox/strings/strings-constants.cjs.js +1 -1
- package/level2/fd-toolbox/strings/strings-constants.js +1 -1
- package/level2/fd-toolbox/strings/strings.cjs.js +1 -1
- package/level2/fd-toolbox/strings/strings.js +1 -1
- package/level2/fd-toolbox/types/ensure-type.cjs.js +1 -1
- package/level2/fd-toolbox/types/ensure-type.js +1 -1
- package/level2/fd-toolbox-core/core/name-of.cjs.js +1 -1
- package/level2/fd-toolbox-core/core/name-of.js +1 -1
- package/level2/fd-toolbox-core/types/resource-with-id.cjs.js +1 -1
- package/level2/fd-toolbox-core/types/resource-with-id.js +1 -1
- package/package.json +1 -1
- 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'](([
|
|
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'](([
|
|
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
|
-
|
|
1
|
+
# Getting Started
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
9
|
+
This tutorial assumes you are using Bash or Git Bash.
|
|
10
|
+
Run in the terminal:
|
|
6
11
|
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
191
|
+
Then we create the role via [upsertRole](/docs/packages/server/functions/upsertRole)
|
|
20
192
|
|
|
21
|
-
|
|
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
|
-
|
|
203
|
+
Next we use the function [createRoleToPermissionIfNotExist](/docs/packages/server/functions/createRoleToPermissionIfNotExist)
|
|
24
204
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
205
|
+
```ts
|
|
206
|
+
await createRoleToPermissionIfNotExist(role.id, [
|
|
207
|
+
studentPermisionId,
|
|
208
|
+
]);
|
|
209
|
+
```
|
|
30
210
|
|
|
31
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
+
#### On frontend
|
|
44
265
|
|
|
45
|
-
|
|
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
|
-
|
|
269
|
+
```ts
|
|
270
|
+
checkAndNotifyCrudPermission(crudActions.create, uiMeta.resourceMeta, studentData);
|
|
271
|
+
```
|
|
48
272
|
|
|
49
|
-
|
|
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
|
-
|
|
275
|
+
#### On backend
|
|
52
276
|
|
|
53
|
-
|
|
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
|
-
|
|
280
|
+
```ts
|
|
281
|
+
const permissionConfig = getPermissionCheckConfig(userId, studentMeta, studentData);
|
|
282
|
+
const hasPermission = await hasPermissionByPermissionCheckConfig(permissionConfig);
|
|
283
|
+
console.log(hasPermission) //false
|
|
284
|
+
```
|
|
56
285
|
|
|
57
|
-
|
|
286
|
+
[hasPermissionByUserId](docs/src/functions/hasPermissionByUserId) — checks whether a user has permission to perform a given CRUD action on a resource.
|
|
58
287
|
|
|
59
|
-
|
|
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
|
-
|
|
295
|
+
If you want to perform custom permission check you can use add [@permissionCheckerFor](docs/src/functions/permissionCheckerFor) decorator.
|
|
62
296
|
|
|
63
|
-
|
|
297
|
+
```ts
|
|
298
|
+
const customChecker: ResourcePermissionChecker = async (
|
|
299
|
+
studentData,
|
|
300
|
+
userId,
|
|
301
|
+
crudActions.create
|
|
302
|
+
) => {
|
|
303
|
+
return userId === userIds.timWId;
|
|
304
|
+
};
|
|
64
305
|
|
|
65
|
-
|
|
306
|
+
@permissionCheckerFor("Student", customChecker)
|
|
307
|
+
@resourceId("d4507481-8b33-46e7-9c2e-606daab170cc")
|
|
308
|
+
export class Student extends WorkspaceResource {...}
|
|
309
|
+
```
|
|
66
310
|
|
|
67
|
-
|
|
311
|
+
In this example only user timW will be able to modify this resource.
|
|
68
312
|
|
|
69
|
-
|
|
313
|
+
## Send notifications
|
|
70
314
|
|
|
71
|
-
|
|
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
|
-
|
|
325
|
+
It will look like this:
|
|
74
326
|
|
|
75
|
-
|
|
327
|
+

|
|
76
328
|
|
|
77
|
-
|
|
329
|
+
#### Sending emails
|
|
78
330
|
|
|
79
|
-
|
|
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
|
-
|
|
360
|
+
It will look like this:
|
|
361
|
+

|
|
82
362
|
|
|
83
|
-
##
|
|
363
|
+
## Add role to a user
|
|
84
364
|
|
|
85
|
-
|
|
365
|
+
To assign a new role to a user, open `UserRole` menu and click `+` button.
|
|
86
366
|
|
|
87
|
-
|
|
367
|
+

|
|
88
368
|
|
|
89
|
-
|
|
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
|
-
|
|
371
|
+

|
|
92
372
|
|
|
93
|
-
|
|
373
|
+
## Assign role to permission
|
|
94
374
|
|
|
95
|
-
|
|
375
|
+
To assign permissions to a role, open the RoleToPermission menu and click the `+` button.
|
|
96
376
|
|
|
97
|
-
|
|
377
|
+

|
|
98
378
|
|
|
99
|
-
|
|
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
|
-
|
|
381
|
+

|
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[
|
|
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`);
|
package/cli/postcss.config.mjs
CHANGED
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
|
+
}
|