-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cdmd4048' into cdmd4058
- Loading branch information
Showing
120 changed files
with
4,644 additions
and
2,530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
.github/ISSUE_TEMPLATE/studio-bug.md → .github/ISSUE_TEMPLATE/platform-issue.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ CLERK_SECRET_KEY= | |
CLERK_JWT_KEY= | ||
CLERK_PUBLISH_KEY= | ||
CLI_TOKEN_TEMPLATE= | ||
|
||
UNKEY_ROOT_KEY= | ||
UNKEY_API_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Should be full url to the Zitadel server | ||
ZITADEL_API_URL= | ||
# Should be the bearer token (can be taken from browser) | ||
ZITADEL_BEARER_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Usage | ||
```bash | ||
node migrate.js | ||
``` | ||
|
||
Copy csv files from clerk to this folder and run the script to migrate the data to the Zitadel. | ||
Environment variables are required to be set in the .env file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import "dotenv/config"; | ||
import axios from "axios"; | ||
import { parse } from "csv/sync"; | ||
import { readFile, readdir } from "fs/promises"; | ||
import z from "zod"; | ||
|
||
const UserSchema = z.object({ | ||
id: z.string(), | ||
first_name: z.string(), | ||
last_name: z.string().optional(), | ||
username: z.string(), | ||
primary_email_address: z.string().email(), | ||
verified_email_addresses: z.string().email(), | ||
}); | ||
|
||
const ZitadelUserSchema = z.object({ | ||
userId: z.string().max(200).optional(), | ||
username: z.string().max(200).optional(), | ||
organization: z | ||
.object({ | ||
orgId: z.string(), | ||
orgDomain: z.string(), | ||
}) | ||
.optional(), | ||
profile: z.object({ | ||
givenName: z.string().min(1).max(200), | ||
familyName: z.string().min(1).max(200), | ||
nickName: z.string().max(200).optional(), | ||
displayName: z.string().max(200).optional(), | ||
preferredLanguage: z.string().max(10).optional(), | ||
gender: z | ||
.enum([ | ||
"GENDER_UNSPECIFIED", | ||
"GENDER_FEMALE", | ||
"GENDER_MALE", | ||
"GENDER_DIVERSE", | ||
]) | ||
.optional(), | ||
}), | ||
email: z.object({ | ||
email: z.string().min(1).max(200), | ||
sendCode: z | ||
.object({ | ||
urlTemplate: z.string().max(2000).optional(), | ||
}) | ||
.optional(), | ||
returnCode: z.object().optional(), | ||
isVerified: z.boolean().optional(), | ||
}), | ||
phone: z | ||
.object({ | ||
phone: z.string().max(200).optional(), | ||
sendCode: z.object().optional(), | ||
returnCode: z.object().optional(), | ||
isVerified: z.boolean().optional(), | ||
}) | ||
.optional(), | ||
metadata: z | ||
.array( | ||
z.object({ | ||
key: z.string().min(1).max(200), | ||
value: z.string().min(1).max(2000), | ||
}), | ||
) | ||
.optional(), | ||
password: z | ||
.object({ | ||
password: z.string().min(1).max(200), | ||
changeRequired: z.boolean().optional(), | ||
}) | ||
.optional(), | ||
hashedPassword: z | ||
.object({ | ||
hash: z.string().min(1).max(200), | ||
changeRequired: z.boolean().optional(), | ||
}) | ||
.optional(), | ||
idpLinks: z | ||
.array( | ||
z.object({ | ||
idpId: z.string().max(200), | ||
userId: z.string().max(200), | ||
userName: z.string().max(200), | ||
}), | ||
) | ||
.optional(), | ||
totpSecret: z.string().max(200).optional(), | ||
}); | ||
|
||
async function createHumanUser(rawUser) { | ||
try { | ||
const user = UserSchema.parse(rawUser); | ||
|
||
const zitadelUser = ZitadelUserSchema.parse({ | ||
userId: user.id, | ||
username: user.username, | ||
profile: { | ||
givenName: user.first_name, | ||
familyName: (user.last_name ?? "").trim() || user.first_name, | ||
}, | ||
email: { | ||
email: user.primary_email_address, | ||
}, | ||
}); | ||
|
||
const response = await axios | ||
.post(`${process.env.ZITADEL_API_URL}/v2/users/human`, zitadelUser, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
Authorization: `Bearer ${process.env.ZITADEL_BEARER_TOKEN}`, | ||
}, | ||
maxBodyLength: Number.POSITIVE_INFINITY, | ||
}) | ||
.then(({ data }) => data); | ||
console.error( | ||
`✅ Created user ${JSON.stringify(zitadelUser)} with response ${JSON.stringify(response)}\n`, | ||
); | ||
} catch (error) { | ||
if (error instanceof z.ZodError) { | ||
console.error( | ||
`⛔️ Error creating user ${JSON.stringify(rawUser)}\n⚠️`, | ||
JSON.stringify(error.format()), | ||
"\n", | ||
); | ||
} else if (axios.isAxiosError(error)) { | ||
console.error( | ||
`⛔️ Error creating user ${JSON.stringify(rawUser)}\n⚠️`, | ||
JSON.stringify(error.response?.data), | ||
"\n", | ||
); | ||
} else { | ||
console.error( | ||
`⛔️ Error creating user ${JSON.stringify(rawUser)}\n⚠️`, | ||
error, | ||
"\n", | ||
); | ||
} | ||
} | ||
} | ||
|
||
const csvFiles = await readdir(".").then((files) => | ||
files.filter((file) => file.endsWith(".csv")), | ||
); | ||
|
||
const records = await Promise.all( | ||
csvFiles.map((filename) => | ||
readFile(filename) | ||
.then((buffer) => parse(buffer)) | ||
.then((lines) => { | ||
const [header, ...records] = lines; | ||
|
||
return records.map((record) => | ||
record.reduce((acc, value, index) => { | ||
acc[header[index]] = value; | ||
return acc; | ||
}, {}), | ||
); | ||
}), | ||
), | ||
).then((records) => records.flat()); | ||
|
||
for (const record of records) { | ||
await createHumanUser(record); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.