serene-core-server 0.1.9 → 0.1.11

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.
@@ -5,6 +5,7 @@ export declare function sereneCoreUsersMutationResolvers(): {
5
5
  userId: string | null;
6
6
  created: Date;
7
7
  updated: Date;
8
+ publicId: string | null;
8
9
  isAdmin: boolean;
9
10
  ownerType: string | null;
10
11
  roles: string[];
@@ -19,6 +20,7 @@ export declare function sereneCoreUsersMutationResolvers(): {
19
20
  userId: string | null;
20
21
  created: Date;
21
22
  updated: Date;
23
+ publicId: string | null;
22
24
  isAdmin: boolean;
23
25
  ownerType: string | null;
24
26
  roles: string[];
@@ -5,6 +5,7 @@ export declare function sereneCoreUsersQueryResolvers(): {
5
5
  userId: string | null;
6
6
  created: Date;
7
7
  updated: Date;
8
+ publicId: string | null;
8
9
  isAdmin: boolean;
9
10
  ownerType: string | null;
10
11
  roles: string[];
@@ -1,7 +1,7 @@
1
1
  import { Prisma } from '@/prisma/client.js';
2
2
  export declare class InstanceModel {
3
3
  clName: string;
4
- create(prisma: Prisma.TransactionClient, parentId: string | null, userProfileId: string, instanceType: string, projectType: string | null, isDemo: boolean, isDefault: boolean, status: string, publicAccess: string | null, key: string, name: string): Promise<{
4
+ create(prisma: Prisma.TransactionClient, publicId: string | null, parentId: string | null, userProfileId: string, instanceType: string, projectType: string | null, isDemo: boolean, isDefault: boolean, status: string, publicAccess: string | null, key: string, name: string): Promise<{
5
5
  name: string;
6
6
  key: string;
7
7
  id: string;
@@ -9,6 +9,7 @@ export declare class InstanceModel {
9
9
  userProfileId: string;
10
10
  created: Date;
11
11
  updated: Date;
12
+ publicId: string | null;
12
13
  parentId: string | null;
13
14
  instanceType: string;
14
15
  projectType: string | null;
@@ -24,6 +25,7 @@ export declare class InstanceModel {
24
25
  userProfileId: string;
25
26
  created: Date;
26
27
  updated: Date;
28
+ publicId: string | null;
27
29
  parentId: string | null;
28
30
  instanceType: string;
29
31
  projectType: string | null;
@@ -37,6 +39,7 @@ export declare class InstanceModel {
37
39
  userId: string | null;
38
40
  created: Date;
39
41
  updated: Date;
42
+ publicId: string | null;
40
43
  isAdmin: boolean;
41
44
  ownerType: string | null;
42
45
  roles: string[];
@@ -50,6 +53,7 @@ export declare class InstanceModel {
50
53
  userProfileId: string;
51
54
  created: Date;
52
55
  updated: Date;
56
+ publicId: string | null;
53
57
  parentId: string | null;
54
58
  instanceType: string;
55
59
  projectType: string | null;
@@ -64,9 +68,10 @@ export declare class InstanceModel {
64
68
  getByParentIdAndName(prisma: Prisma.TransactionClient, parentId: string | null, name: string): Promise<any>;
65
69
  getByParentIdAndKeyAndUserProfileId(prisma: Prisma.TransactionClient, parentId: string | null, key: string, userProfileId: string): Promise<any>;
66
70
  getByParentIdAndNameAndUserProfileId(prisma: Prisma.TransactionClient, parentId: string | null, name: string, userProfileId: string): Promise<any>;
71
+ getByPublicId(prisma: Prisma.TransactionClient, publicId: string): Promise<any>;
67
72
  getByUserProfileIdAndName(prisma: Prisma.TransactionClient, userProfileId: string, name: string): Promise<any>;
68
73
  getByUserProfileIdAndParentNameAndName(prisma: Prisma.TransactionClient, userProfileId: string, parentName: string, name: string): Promise<any>;
69
- update(prisma: Prisma.TransactionClient, id: string, parentId: string | null | undefined, userProfileId: string | undefined, instanceType: string | undefined, projectType: string | null | undefined, isDemo: boolean | undefined, isDefault: boolean | undefined, status: string | undefined, publicAccess: string | null | undefined, key: string | undefined, name: string | undefined): Promise<{
74
+ update(prisma: Prisma.TransactionClient, id: string, publicId: string | null | undefined, parentId: string | null | undefined, userProfileId: string | undefined, instanceType: string | undefined, projectType: string | null | undefined, isDemo: boolean | undefined, isDefault: boolean | undefined, status: string | undefined, publicAccess: string | null | undefined, key: string | undefined, name: string | undefined): Promise<{
70
75
  name: string;
71
76
  key: string;
72
77
  id: string;
@@ -74,6 +79,7 @@ export declare class InstanceModel {
74
79
  userProfileId: string;
75
80
  created: Date;
76
81
  updated: Date;
82
+ publicId: string | null;
77
83
  parentId: string | null;
78
84
  instanceType: string;
79
85
  projectType: string | null;
@@ -82,7 +88,7 @@ export declare class InstanceModel {
82
88
  publicAccess: string | null;
83
89
  }>;
84
90
  updateByParentId(prisma: Prisma.TransactionClient, parentId: string | null | undefined, userProfileId: string | undefined, instanceType: string | undefined, projectType: string | null | undefined, isDemo: boolean | undefined, isDefault: boolean | undefined, status: string | undefined, publicAccess: string | null | undefined, key: string | undefined, name: string | undefined): Promise<Prisma.BatchPayload>;
85
- upsert(prisma: Prisma.TransactionClient, id: string | undefined, parentId: string | null | undefined, userProfileId: string | undefined, instanceType: string | undefined, projectType: string | null | undefined, isDemo: boolean | undefined, isDefault: boolean | undefined, status: string | undefined, publicAccess: string | null | undefined, key: string | undefined, name: string | undefined): Promise<{
91
+ upsert(prisma: Prisma.TransactionClient, id: string | undefined, publicId: string | null | undefined, parentId: string | null | undefined, userProfileId: string | undefined, instanceType: string | undefined, projectType: string | null | undefined, isDemo: boolean | undefined, isDefault: boolean | undefined, status: string | undefined, publicAccess: string | null | undefined, key: string | undefined, name: string | undefined): Promise<{
86
92
  name: string;
87
93
  key: string;
88
94
  id: string;
@@ -90,6 +96,7 @@ export declare class InstanceModel {
90
96
  userProfileId: string;
91
97
  created: Date;
92
98
  updated: Date;
99
+ publicId: string | null;
93
100
  parentId: string | null;
94
101
  instanceType: string;
95
102
  projectType: string | null;
@@ -1,14 +1,16 @@
1
+ import { CustomError } from '../../types/errors.js';
1
2
  export class InstanceModel {
2
3
  // Consts
3
4
  clName = 'InstanceModel';
4
5
  // Code
5
- async create(prisma, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name) {
6
+ async create(prisma, publicId, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name) {
6
7
  // Debug
7
8
  const fnName = `${this.clName}.create()`;
8
9
  // Create record
9
10
  try {
10
11
  return await prisma.instance.create({
11
12
  data: {
13
+ publicId: publicId,
12
14
  parent: parentId != null ? {
13
15
  connect: {
14
16
  id: parentId
@@ -305,6 +307,36 @@ export class InstanceModel {
305
307
  // Return
306
308
  return instance;
307
309
  }
310
+ async getByPublicId(prisma, publicId) {
311
+ // Debug
312
+ const fnName = `${this.clName}.getByPublicId()`;
313
+ // Validate
314
+ if (publicId == null) {
315
+ throw new CustomError(`${fnName}: publicId == null`);
316
+ }
317
+ // Query
318
+ var instance;
319
+ try {
320
+ instance = await prisma.instance.findFirst({
321
+ include: {
322
+ userProfile: {
323
+ include: {
324
+ user: true
325
+ }
326
+ }
327
+ },
328
+ where: {
329
+ publicId: publicId
330
+ }
331
+ });
332
+ }
333
+ catch (error) {
334
+ console.error(`${fnName}: error: ${error}`);
335
+ throw 'Prisma error';
336
+ }
337
+ // Return
338
+ return instance;
339
+ }
308
340
  async getByUserProfileIdAndName(prisma, userProfileId, name) {
309
341
  // Debug
310
342
  const fnName = `${this.clName}.getByUserProfileIdAndName()`;
@@ -377,13 +409,14 @@ export class InstanceModel {
377
409
  // Return
378
410
  return instance;
379
411
  }
380
- async update(prisma, id, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name) {
412
+ async update(prisma, id, publicId, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name) {
381
413
  // Debug
382
414
  const fnName = `${this.clName}.update()`;
383
415
  // Update record
384
416
  try {
385
417
  return await prisma.instance.update({
386
418
  data: {
419
+ publicId: publicId,
387
420
  parentId: parentId,
388
421
  userProfileId: userProfileId,
389
422
  instanceType: instanceType,
@@ -432,7 +465,7 @@ export class InstanceModel {
432
465
  throw 'Prisma error';
433
466
  }
434
467
  }
435
- async upsert(prisma, id, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name) {
468
+ async upsert(prisma, id, publicId, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name) {
436
469
  // Debug
437
470
  const fnName = `${this.clName}.upsert()`;
438
471
  // If id isn't specified, try to get by a unique key
@@ -457,6 +490,10 @@ export class InstanceModel {
457
490
  // Upsert
458
491
  if (id == null) {
459
492
  // Validate for create (mainly for type validation of the create call)
493
+ if (publicId === undefined) {
494
+ console.error(`${fnName}: id is null and publicId is undefined`);
495
+ throw 'Prisma error';
496
+ }
460
497
  if (parentId === undefined) {
461
498
  console.error(`${fnName}: id is null and parentId is undefined`);
462
499
  throw 'Prisma error';
@@ -498,11 +535,11 @@ export class InstanceModel {
498
535
  throw 'Prisma error';
499
536
  }
500
537
  // Create
501
- return await this.create(prisma, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name);
538
+ return await this.create(prisma, publicId, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name);
502
539
  }
503
540
  else {
504
541
  // Update
505
- return await this.update(prisma, id, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name);
542
+ return await this.update(prisma, id, publicId, parentId, userProfileId, instanceType, projectType, isDemo, isDefault, status, publicAccess, key, name);
506
543
  }
507
544
  }
508
545
  }
@@ -1,11 +1,12 @@
1
1
  import { PrismaClient } from '@/prisma/client.js';
2
2
  export declare class UserProfileModel {
3
3
  clName: string;
4
- create(prisma: PrismaClient, userId: string | null, isAdmin: boolean, deletePending: Date | null): Promise<{
4
+ create(prisma: PrismaClient, publicId: string | null, userId: string | null, isAdmin: boolean, deletePending: Date | null): Promise<{
5
5
  id: string;
6
6
  userId: string | null;
7
7
  created: Date;
8
8
  updated: Date;
9
+ publicId: string | null;
9
10
  isAdmin: boolean;
10
11
  ownerType: string | null;
11
12
  roles: string[];
@@ -16,6 +17,18 @@ export declare class UserProfileModel {
16
17
  userId: string | null;
17
18
  created: Date;
18
19
  updated: Date;
20
+ publicId: string | null;
21
+ isAdmin: boolean;
22
+ ownerType: string | null;
23
+ roles: string[];
24
+ deletePending: Date | null;
25
+ } | null | undefined>;
26
+ getByPublicId(prisma: PrismaClient, publicId: string): Promise<{
27
+ id: string;
28
+ userId: string | null;
29
+ created: Date;
30
+ updated: Date;
31
+ publicId: string | null;
19
32
  isAdmin: boolean;
20
33
  ownerType: string | null;
21
34
  roles: string[];
@@ -26,6 +39,7 @@ export declare class UserProfileModel {
26
39
  userId: string | null;
27
40
  created: Date;
28
41
  updated: Date;
42
+ publicId: string | null;
29
43
  isAdmin: boolean;
30
44
  ownerType: string | null;
31
45
  roles: string[];
@@ -35,21 +49,23 @@ export declare class UserProfileModel {
35
49
  status: boolean;
36
50
  userProfile: any;
37
51
  }>;
38
- update(prisma: PrismaClient, id: string, userId: string | null | undefined, isAdmin: boolean | undefined, deletePending: Date | null | undefined): Promise<{
52
+ update(prisma: PrismaClient, id: string, publicId: string | null | undefined, userId: string | null | undefined, isAdmin: boolean | undefined, deletePending: Date | null | undefined): Promise<{
39
53
  id: string;
40
54
  userId: string | null;
41
55
  created: Date;
42
56
  updated: Date;
57
+ publicId: string | null;
43
58
  isAdmin: boolean;
44
59
  ownerType: string | null;
45
60
  roles: string[];
46
61
  deletePending: Date | null;
47
62
  }>;
48
- upsert(prisma: PrismaClient, id: string | undefined, userId: string | null | undefined, isAdmin: boolean | undefined, deletePending: Date | null | undefined): Promise<{
63
+ upsert(prisma: PrismaClient, id: string | undefined, publicId: string | null | undefined, userId: string | null | undefined, isAdmin: boolean | undefined, deletePending: Date | null | undefined): Promise<{
49
64
  id: string;
50
65
  userId: string | null;
51
66
  created: Date;
52
67
  updated: Date;
68
+ publicId: string | null;
53
69
  isAdmin: boolean;
54
70
  ownerType: string | null;
55
71
  roles: string[];
@@ -1,15 +1,17 @@
1
+ import { CustomError } from '../../types/errors.js';
1
2
  import { UserTypes } from '../../types/user-types.js';
2
3
  export class UserProfileModel {
3
4
  // Consts
4
5
  clName = 'UserProfileModel';
5
6
  // Code
6
- async create(prisma, userId, isAdmin, deletePending) {
7
+ async create(prisma, publicId, userId, isAdmin, deletePending) {
7
8
  // Debug
8
9
  const fnName = `${this.clName}.create()`;
9
10
  // Create record
10
11
  try {
11
12
  return await prisma.userProfile.create({
12
13
  data: {
14
+ publicId: publicId,
13
15
  userId: userId,
14
16
  isAdmin: isAdmin,
15
17
  deletePending: deletePending
@@ -39,9 +41,35 @@ export class UserProfileModel {
39
41
  }
40
42
  }
41
43
  }
44
+ async getByPublicId(prisma, publicId) {
45
+ // Debug
46
+ const fnName = `${this.clName}.getByPublicId()`;
47
+ // Validate
48
+ if (publicId == null) {
49
+ throw new CustomError(`${fnName}: publicId == null`);
50
+ }
51
+ // Get record
52
+ try {
53
+ return await prisma.userProfile.findFirst({
54
+ where: {
55
+ publicId: publicId
56
+ }
57
+ });
58
+ }
59
+ catch (error) {
60
+ if (!(error instanceof error.NotFound)) {
61
+ console.error(`${fnName}: error: ${error}`);
62
+ throw 'Prisma error';
63
+ }
64
+ }
65
+ }
42
66
  async getByUserId(prisma, userId) {
43
67
  // Debug
44
68
  const fnName = `${this.clName}.getByUserId()`;
69
+ // Validate
70
+ if (userId == null) {
71
+ throw new CustomError(`${fnName}: userId == null`);
72
+ }
45
73
  // Get record
46
74
  try {
47
75
  return await prisma.userProfile.findFirst({
@@ -60,8 +88,8 @@ export class UserProfileModel {
60
88
  async setOwnerType(prisma, userProfile) {
61
89
  // Debug
62
90
  const fnName = `${this.clName}.setOwnerType()`;
63
- console.log(`${fnName}: starting with userProfile: ` +
64
- JSON.stringify(userProfile));
91
+ // console.log(`${fnName}: starting with userProfile: ` +
92
+ // JSON.stringify(userProfile))
65
93
  // Return immediately if ownerType is set
66
94
  if (userProfile.ownerType != null) {
67
95
  return {
@@ -89,13 +117,14 @@ export class UserProfileModel {
89
117
  userProfile: userProfile
90
118
  };
91
119
  }
92
- async update(prisma, id, userId, isAdmin, deletePending) {
120
+ async update(prisma, id, publicId, userId, isAdmin, deletePending) {
93
121
  // Debug
94
122
  const fnName = `${this.clName}.update()`;
95
123
  // Create record
96
124
  try {
97
125
  return await prisma.userProfile.update({
98
126
  data: {
127
+ publicId: publicId,
99
128
  userId: userId,
100
129
  isAdmin: isAdmin
101
130
  },
@@ -109,7 +138,7 @@ export class UserProfileModel {
109
138
  throw 'Prisma error';
110
139
  }
111
140
  }
112
- async upsert(prisma, id, userId, isAdmin, deletePending) {
141
+ async upsert(prisma, id, publicId, userId, isAdmin, deletePending) {
113
142
  // Debug
114
143
  const fnName = `${this.clName}.upsert()`;
115
144
  // If id isn't specified, but the unique keys are, try to get the record
@@ -123,6 +152,10 @@ export class UserProfileModel {
123
152
  // Upsert
124
153
  if (id == null) {
125
154
  // Validate for create (mainly for type validation of the create call)
155
+ if (publicId === undefined) {
156
+ console.error(`${fnName}: id is null and publicId is undefined`);
157
+ throw 'Prisma error';
158
+ }
126
159
  if (userId === undefined) {
127
160
  console.error(`${fnName}: id is null and userId is undefined`);
128
161
  throw 'Prisma error';
@@ -136,11 +169,11 @@ export class UserProfileModel {
136
169
  throw 'Prisma error';
137
170
  }
138
171
  // Create
139
- return await this.create(prisma, userId, isAdmin, deletePending);
172
+ return await this.create(prisma, publicId, userId, isAdmin, deletePending);
140
173
  }
141
174
  else {
142
175
  // Update
143
- return await this.update(prisma, id, userId, isAdmin, deletePending);
176
+ return await this.update(prisma, id, publicId, userId, isAdmin, deletePending);
144
177
  }
145
178
  }
146
179
  }
@@ -15,7 +15,8 @@ export class ExternalUserIntegrationService {
15
15
  return externalUserIntegration.userProfileId;
16
16
  }
17
17
  // Create UserProfile record
18
- const userProfile = await this.userProfileModel.create(prisma, null, // userId
18
+ const userProfile = await this.userProfileModel.create(prisma, null, // publicId
19
+ null, // userId
19
20
  false, // isAdmin
20
21
  null); // deletePending
21
22
  // Create ExternalUserIntegration record
@@ -12,6 +12,7 @@ export declare class UsersService {
12
12
  userId: string | null;
13
13
  created: Date;
14
14
  updated: Date;
15
+ publicId: string | null;
15
16
  isAdmin: boolean;
16
17
  ownerType: string | null;
17
18
  roles: string[];
@@ -24,6 +25,7 @@ export declare class UsersService {
24
25
  userId: string | null;
25
26
  created: Date;
26
27
  updated: Date;
28
+ publicId: string | null;
27
29
  isAdmin: boolean;
28
30
  ownerType: string | null;
29
31
  roles: string[];
@@ -44,6 +46,7 @@ export declare class UsersService {
44
46
  userId: string | null;
45
47
  created: Date;
46
48
  updated: Date;
49
+ publicId: string | null;
47
50
  isAdmin: boolean;
48
51
  ownerType: string | null;
49
52
  roles: string[];
@@ -54,6 +57,7 @@ export declare class UsersService {
54
57
  userId: string | null;
55
58
  created: Date;
56
59
  updated: Date;
60
+ publicId: string | null;
57
61
  isAdmin: boolean;
58
62
  ownerType: string | null;
59
63
  roles: string[];
@@ -13,7 +13,8 @@ export class UsersService {
13
13
  // Code
14
14
  async createBlankUser(prisma) {
15
15
  // console.log('UsersService.createBlankUser(): start')
16
- return await this.userProfileModel.create(prisma, null, // userId
16
+ return await this.userProfileModel.create(prisma, null, // publicId
17
+ null, // userId
17
18
  false, // isAdmin
18
19
  null); // deletePending
19
20
  }
@@ -30,7 +31,8 @@ export class UsersService {
30
31
  }
31
32
  async createUserByEmail(prisma, email) {
32
33
  const user = await this.userModel.create(prisma, email, undefined); // name
33
- const userProfile = await this.userProfileModel.create(prisma, user.id, false, // isAdmin
34
+ const userProfile = await this.userProfileModel.create(prisma, null, // publicId
35
+ user.id, false, // isAdmin
34
36
  null); // deletePending
35
37
  return userProfile.id;
36
38
  }
@@ -100,7 +102,8 @@ export class UsersService {
100
102
  // console.log(`signedInUserProfile: ` + JSON.stringify(signedInUserProfile))
101
103
  if (signedInUserProfile == null) {
102
104
  // Create userProfile record
103
- signedInUserProfile = await this.userProfileModel.create(prisma, signedInUser.id, // userId
105
+ signedInUserProfile = await this.userProfileModel.create(prisma, null, // publicId
106
+ signedInUser.id, // userId
104
107
  false, // isAdmin
105
108
  null); // deletePending
106
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serene-core-server",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",