@openinc/parse-server-opendash 3.25.1 → 3.25.2

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.
@@ -76,19 +76,31 @@ async function init(name) {
76
76
  const defaultTenant = await new Parse.Query(types_1.Tenant)
77
77
  .ascending("createdAt")
78
78
  .first({ useMasterKey: true });
79
- let user = await new Parse.Query(Parse.User)
79
+ let user = (await new Parse.Query(Parse.User)
80
+ .equalTo("microsoftId", verifiedPayload.oid)
81
+ .first({ useMasterKey: true }));
82
+ // Legacy fallback: some older accounts might have been created using the oid as username.
83
+ let oldUser = (await new Parse.Query(Parse.User)
80
84
  .equalTo("username", verifiedPayload.oid)
81
- .first({ useMasterKey: true });
82
- if (!user) {
85
+ .first({ useMasterKey: true }));
86
+ if (!user && !oldUser) {
83
87
  user = new Parse.User();
84
- user.set("username", verifiedPayload.oid);
88
+ user.set("username", account.username);
85
89
  user.set("email", account.username);
86
90
  user.set("password", (0, crypto_1.randomBytes)(16).toString("hex"));
91
+ user.set("microsoftId", verifiedPayload.oid);
87
92
  user.set("name", verifiedPayload.name || verifiedPayload.preferred_username);
88
93
  user.set("tenant", defaultTenant);
89
94
  user = await user.signUp(null, { useMasterKey: true });
90
95
  return user.getSessionToken();
91
96
  }
97
+ else if (!user && oldUser) {
98
+ // Migrate legacy account that used the oid as username to a modern record keyed by microsoftId.
99
+ user = oldUser;
100
+ user.set("microsoftId", verifiedPayload.oid);
101
+ user.set("username", account.username);
102
+ user = await user.save(null, { useMasterKey: true });
103
+ }
92
104
  const sessionToken = "r:" + (0, crypto_1.randomBytes)(16).toString("hex");
93
105
  const session = new Parse.Object("_Session");
94
106
  session.set("user", user);
@@ -15,6 +15,7 @@ export interface _UserAttributes {
15
15
  miaas_cities: any[];
16
16
  miaas_userType?: string | undefined;
17
17
  miaasUserScope?: string | undefined;
18
+ microsoftId?: string | undefined;
18
19
  name?: string | undefined;
19
20
  password?: string | undefined;
20
21
  settings?: User_Setting | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "3.25.1",
3
+ "version": "3.25.2",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "keywords": [