Skip to content

Commit

Permalink
Merge branch 'cdmd4048' into cdmd4058
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksy Rybicki authored and Aleksy Rybicki committed Jan 27, 2025
2 parents df495f0 + f63d45a commit c48373c
Show file tree
Hide file tree
Showing 120 changed files with 4,644 additions and 2,530 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@
"contributions": [
"doc"
]
},
{
"login": "spirulence",
"name": "Cameron Seebach",
"avatar_url": "https://avatars.githubusercontent.com/u/1297151?v=4",
"profile": "https://github.com/spirulence",
"contributions": [
"bug",
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Codemod Studio
about: Report any issues, feedback, or feature requests for Codemod Studio.
title: "[studio]"
labels: studio
name: Platform Issue
about: Report any issues, feedback, or feature requests for Codemod Platform.
title: "[issue-name]"
labels: platform
assignees: ''

---
Expand Down
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/report-faulty-codemod.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
name: Faulty codemod
about: Report issues with an existing codemod.
title: "[codemod][FP/FN] <codemod-name>"
labels: codemod-issue
labels: codemod-issue, studio
assignees: ''

---


### Faulty codemod

1. Mention the codemod name, e.g., `react/19/remove-forward-ref`
Expand Down
4 changes: 0 additions & 4 deletions .github/ISSUE_TEMPLATE/request-codemod.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ To contributors working on this task:
- [ ] **Codemod Creator**: [Build](https://go.codemod.com/build-codemod-docs) and [publish](https://go.codemod.com/codemod-publish-doc) quality codemods that handle most edge cases. False negatives are acceptable, but there should be no false positives. Even if the transformation is tricky, build a codemod that can detect and add comments to guide developers to the areas needing manual changes.

- Questions? -> [Community](https://go.codemod.com/community)




1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Yugal41735"><img src="https://avatars.githubusercontent.com/u/74638775?v=4?s=100" width="100px;" alt="Yugal Agarwal"/><br /><sub><b>Yugal Agarwal</b></sub></a><br /><a href="https://github.com/codemod-com/codemod/commits?author=Yugal41735" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/poswalsameer"><img src="https://avatars.githubusercontent.com/u/106386145?v=4?s=100" width="100px;" alt="Sameer Poswal"/><br /><sub><b>Sameer Poswal</b></sub></a><br /><a href="https://github.com/codemod-com/codemod/commits?author=poswalsameer" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/stramel"><img src="https://avatars.githubusercontent.com/u/855184?v=4?s=100" width="100px;" alt="Michael Stramel"/><br /><sub><b>Michael Stramel</b></sub></a><br /><a href="https://github.com/codemod-com/codemod/commits?author=stramel" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/spirulence"><img src="https://avatars.githubusercontent.com/u/1297151?v=4?s=100" width="100px;" alt="Cameron Seebach"/><br /><sub><b>Cameron Seebach</b></sub></a><br /><a href="https://github.com/codemod-com/codemod/issues?q=author%3Aspirulence" title="Bug reports">🐛</a> <a href="https://github.com/codemod-com/codemod/commits?author=spirulence" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
3 changes: 3 additions & 0 deletions apps/auth-service/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ CLERK_SECRET_KEY=
CLERK_JWT_KEY=
CLERK_PUBLISH_KEY=
CLI_TOKEN_TEMPLATE=

UNKEY_ROOT_KEY=
UNKEY_API_ID=
6 changes: 6 additions & 0 deletions apps/auth-service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @codemod-com/auth-service

## 0.0.17

### Patch Changes

- 149e6e0: Add API key functionality

## 0.0.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ esbuild
.build({
entryPoints: ["src/index.ts"],
bundle: true,
minify: true,
minify: false,
platform: "node",
outfile: "build/index.js",
banner: {
Expand Down
4 changes: 4 additions & 0 deletions apps/auth-service/migrate/.env.example
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=
2 changes: 2 additions & 0 deletions apps/auth-service/migrate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
*.csv
7 changes: 7 additions & 0 deletions apps/auth-service/migrate/README.md
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.
165 changes: 165 additions & 0 deletions apps/auth-service/migrate/migrate.js
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);
}
6 changes: 4 additions & 2 deletions apps/auth-service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codemod-com/auth-service",
"version": "0.0.16",
"version": "0.0.17",
"scripts": {
"build": "tsc && node esbuild.config.js",
"start": "node build/index.js"
Expand All @@ -18,7 +18,8 @@
"esbuild": "^0.19.12",
"esbuild-plugin-copy": "catalog:",
"ts-node": "10.9.2",
"tsx": "^4.7.1"
"tsx": "^4.7.1",
"csv": "6.3.11"
},
"dependencies": {
"@clerk/backend": "catalog:",
Expand All @@ -29,6 +30,7 @@
"@fastify/busboy": "catalog:",
"@fastify/cors": "catalog:",
"@fastify/rate-limit": "catalog:",
"@unkey/api": "catalog:",
"axios": "catalog:",
"dotenv": "catalog:",
"fastify": "catalog:",
Expand Down
4 changes: 4 additions & 0 deletions apps/auth-service/src/schemata/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const environmentSchema = object({
CLERK_SECRET_KEY: string(),
CLERK_JWT_KEY: string(),
APP_TOKEN_TEMPLATE: string(),
ZITADEL_URL: string(),
AUTH_OPENID_ISSUER: string(),
CLIENT_ID: string(),
REDIRECT_URL: string(),
VERIFIED_PUBLISHERS: pipe(
unknown(),
transform((input) => {
Expand Down
Loading

0 comments on commit c48373c

Please sign in to comment.