Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(codegen): INFRA-316 update app00 template and add backend miniapp template #4708

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d38ff7c
refactor(codegen): INFRA-219 base update app template
nomerdvadcatpyat Apr 26, 2024
72edc02
refactor(codegen): INFRA-316 added backend app template
nomerdvadcatpyat May 7, 2024
ff4bd32
refactor(codegen): INFRA-316 added nosonar comments
nomerdvadcatpyat May 7, 2024
e0200fe
fix(codegen): INFRA-316 update app types
nomerdvadcatpyat May 30, 2024
c66998c
fix(codegen): INFRA-316 move generateCondoSchema to codegen package
nomerdvadcatpyat May 30, 2024
12f7a35
fix(codegen): INFRA-316 some fixes
nomerdvadcatpyat May 30, 2024
8857134
fix(codegen): INFRA-316 update components in template
nomerdvadcatpyat May 30, 2024
48a6678
fix(codegen): INFRA-316 remove some redundant code, move generate.con…
nomerdvadcatpyat Jun 13, 2024
cb21e2a
fix(codegen): INFRA-316 update yarn.lock
nomerdvadcatpyat Jun 13, 2024
1ae22a3
feat(condo): INFRA-316 added todo to move oidc logic to separate comp…
nomerdvadcatpyat Jun 21, 2024
ffbc88c
feat(condo): INFRA-316 fix tests in template
nomerdvadcatpyat Jun 21, 2024
4bbcd31
feat(condo): INFRA-316 fix tests in app01
nomerdvadcatpyat Jun 21, 2024
4b6e640
fix(codegen): INFRA-316 some fixes
nomerdvadcatpyat Jul 3, 2024
d122550
fix(codegen): INFRA-316 added info about prepare in README
nomerdvadcatpyat Jul 8, 2024
7cb035c
feat(codegen): INFRA-316 update oidc middleware in backend app
nomerdvadcatpyat Jul 29, 2024
53bfa7a
feat(codegen): INFRA-316 use values for session headers from envs
nomerdvadcatpyat Jul 29, 2024
380a2a0
feat(codegen): INFRA-316 change start route of backend miniapp
nomerdvadcatpyat Jul 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions apps/condo/bin/create-b2bapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')

const { faker } = require('@faker-js/faker')

const { updateAppEnvFile } = require('@open-condo/cli')
const { prepareKeystoneExpressApp } = require('@open-condo/keystone/prepareKeystoneApp')

const { B2BApp } = require('@condo/domains/miniapp/utils/serverSchema')
Expand All @@ -15,34 +16,41 @@ function getJson (data) {
}

async function main (args) {
const [name, options] = args
const [b2bAppName, options, appName] = args
let optionsJson = getJson(options)
if (!name) throw new Error('use: create-b2bapp <name> [<options>]')
if (!b2bAppName) throw new Error('use: create-b2bapp <name> [<options>]')
if (options && !optionsJson) throw new Error('<options> argument should be a valid json')
if (options && !optionsJson.appUrl) throw new Error('<options> argument should have appUrl key')
const json = optionsJson || {}

const { keystone: context } = await prepareKeystoneExpressApp(path.resolve('./index.js'), { excludeApps: ['NextApp', 'AdminUIApp'] })

console.info(`NAME: ${name}`)
const [b2bapp] = await B2BApp.getAll(context, { name }, { first: 1, sortBy: ['createdAt_DESC'] })
console.info(`NAME: ${b2bAppName}`)
let b2bAppId
const [b2bApp] = await B2BApp.getAll(context, { name: b2bAppName }, { first: 1, sortBy: ['createdAt_DESC'] })
if (!json.dv) json.dv = 1
if (!json.sender) json.sender = { 'dv': 1, 'fingerprint': 'create-b2bapp-script' }
if (!b2bapp) {
if (!b2bApp) {
if (!json.contextDefaultStatus) json.contextDefaultStatus = 'Finished'
if (!json.category) json.category = 'OTHER'
if (!json.developer) json.developer = 'InternalDeveloper'
if (!json.shortDescription) json.shortDescription = faker.commerce.productDescription()
if (!json.detailedDescription) json.detailedDescription = faker.lorem.paragraphs(5)

await B2BApp.create(context, {
name, ...json,
const b2bApp = await B2BApp.create(context, {
name: b2bAppName, ...json,
})
b2bAppId = b2bApp.id
console.info('B2BApp created!')
} else {
await B2BApp.update(context, b2bapp.id, json)
await B2BApp.update(context, b2bApp.id, json)
b2bAppId = b2bApp.id
console.info('B2BApp updated!')
}

if (appName) {
await updateAppEnvFile(appName, 'CONDO_B2B_APP_ID', b2bAppId)
}
}

main(process.argv.slice(2)).then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class OidcModelClientAdapter {
* - iat {number} - timestamp of the replay object cache's creation
*/
const expiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1000) : undefined
const { isEnabled, ...clientPayload } = payload
const dvAndSender = {
dv: 1,
sender: {
Expand All @@ -167,9 +168,9 @@ class OidcModelClientAdapter {
}
const item = await OidcClient.getOne(this.context, { clientId: id, deletedAt: null })
if (!item) {
return await OidcClient.create(this.context, { ...dvAndSender, clientId: id, payload, expiresAt })
return await OidcClient.create(this.context, { ...dvAndSender, clientId: id, payload: clientPayload, isEnabled, expiresAt })
} else {
return await OidcClient.update(this.context, item.id, { ...dvAndSender, clientId: id, payload, expiresAt })
return await OidcClient.update(this.context, item.id, { ...dvAndSender, clientId: id, payload: clientPayload, isEnabled, expiresAt })
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ async function prepareCondoAppOidcConfig (appName) {
return { serverUrl, clientId, clientSecret }
}

async function prepareCondoAppB2BAppConfig (appName, p2pAppName) {
const appUrl = await getAppServerUrl(appName)
async function prepareCondoAppB2BAppConfig (appName, b2bAppName, withLaunchRoute) {
let appUrl = await getAppServerUrl(appName)
appUrl = withLaunchRoute ? (appUrl + '/launch') : appUrl
const opts = JSON.stringify({ appUrl, displayPriority: 2 })
await safeExec(`yarn workspace @app/condo node ./bin/create-b2bapp.js ${p2pAppName} ${JSON.stringify(opts)}`)
await safeExec(`yarn workspace @app/condo node ./bin/create-b2bapp.js ${b2bAppName} ${JSON.stringify(opts)} ${appName}`)
return { appUrl }
}

Expand Down
Loading
Loading