-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update dependency on @logto/cloud and update legacy JWT cus…
…tomizer
- Loading branch information
Showing
8 changed files
with
123 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,6 @@ | |
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"@logto/cloud": "0.2.5-6c090b2" | ||
"@logto/cloud": "0.2.5-1807f9c" | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
packages/schemas/alterations/next-1712132946-rename-jwt-customizer-field.ts
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,105 @@ | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
enum LogtoJwtTokenKey { | ||
AccessToken = 'jwt.accessToken', | ||
ClientCredentials = 'jwt.clientCredentials', | ||
} | ||
|
||
type OldJwtCustomizer = { | ||
[x: string]: unknown; | ||
envVars?: Record<string, string>; | ||
}; | ||
|
||
type OldJwtCustomizerRow = { | ||
tenantId: string; | ||
key: LogtoJwtTokenKey; | ||
value: OldJwtCustomizer; | ||
}; | ||
|
||
type NewJwtCustomizer = { | ||
[x: string]: unknown; | ||
environmentVariables?: Record<string, string>; | ||
}; | ||
|
||
type NewJwtCustomizerRow = { | ||
tenantId: string; | ||
key: LogtoJwtTokenKey; | ||
value: NewJwtCustomizer; | ||
}; | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
const { rows } = await pool.query<OldJwtCustomizerRow>(sql` | ||
select * from logto_configs | ||
where key in (${LogtoJwtTokenKey.AccessToken}, ${LogtoJwtTokenKey.ClientCredentials}); | ||
`); | ||
|
||
if (rows.length === 0) { | ||
return; | ||
} | ||
|
||
await Promise.all( | ||
rows.map(async (row) => { | ||
const { | ||
tenantId, | ||
key, | ||
value: { envVars, ...rest }, | ||
} = row; | ||
|
||
if (!envVars) { | ||
return; | ||
} | ||
|
||
const newJwtCustomizer: NewJwtCustomizer = { | ||
environmentVariables: envVars, | ||
...rest, | ||
}; | ||
|
||
await pool.query(sql` | ||
update logto_configs | ||
set value = ${JSON.stringify(newJwtCustomizer)} | ||
where tenant_id = ${tenantId} and key = ${key}; | ||
`); | ||
}) | ||
); | ||
}, | ||
down: async (pool) => { | ||
const { rows } = await pool.query<NewJwtCustomizerRow>(sql` | ||
select * from logto_configs | ||
where key in (${LogtoJwtTokenKey.AccessToken}, ${LogtoJwtTokenKey.ClientCredentials}); | ||
`); | ||
|
||
if (rows.length === 0) { | ||
return; | ||
} | ||
|
||
await Promise.all( | ||
rows.map(async (row) => { | ||
const { | ||
tenantId, | ||
key, | ||
value: { environmentVariables, ...rest }, | ||
} = row; | ||
|
||
if (!environmentVariables) { | ||
return; | ||
} | ||
|
||
const oldJwtCustomizer: OldJwtCustomizer = { | ||
envVars: environmentVariables, | ||
...rest, | ||
}; | ||
|
||
await pool.query(sql` | ||
update logto_configs | ||
set value = ${JSON.stringify(oldJwtCustomizer)} | ||
where tenant_id = ${tenantId} and key = ${key}; | ||
`); | ||
}) | ||
); | ||
}, | ||
}; | ||
|
||
export default alteration; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.