@sap/cds-mtxs
Advanced tools
Comparing version 1.9.0 to 1.9.1
@@ -9,2 +9,8 @@ # Change Log | ||
## Version 1.9.1 - 2023-07-06 | ||
### Fixed | ||
- `GET /-/cds/saas-provisioning/tenant` now doesn't include a duplicate `tenant` field, but only provides the tenant via `subscribedTenantId`. | ||
## Version 1.9.0 - 2023-06-22 | ||
@@ -16,3 +22,3 @@ | ||
- Upgrade now checks if MTXS Migration has been done if old extensions exist and if extensibility is properly configured. | ||
- `GET /-/cds/saas-provisioning/tenant` now returns a `tenant` field, even if the tenant was onboarded with no metadata. | ||
- `GET /-/cds/saas-provisioning/tenant` now returns a `subscribedTenantId` field, even if the tenant was onboarded with no metadata. | ||
- Token resource now accepts the POST method (can be used with @sap/cds-dk version 7). | ||
@@ -19,0 +25,0 @@ |
@@ -39,3 +39,4 @@ const path = require('path') | ||
} catch (error) { | ||
if (!error.code === 'MODEL_NOT_FOUND') throw error | ||
if (error.code !== 'MODEL_NOT_FOUND') throw error | ||
// ignore extensions with no model | ||
continue | ||
@@ -83,3 +84,7 @@ } | ||
} | ||
// add compiler settings from main | ||
packageJson.cds.cdsc = cds.env.cdsc | ||
await fs.writeFile(path.join(dir, 'package.json'), JSON.stringify(packageJson, 2)) | ||
} |
@@ -132,2 +132,18 @@ const path = require('path') | ||
module.exports.getMissingMtxTenants = async (existingTenants) => { | ||
if (await mtxAdapter.wasOldMtx()) { | ||
// TODO do this only once | ||
// get all mtx tenants | ||
const mtxTenants = await mtxAdapter.getAllTenantIds() | ||
// add metadata for non-existing entries | ||
return await Promise.all(mtxTenants.filter( mtxTenant => !existingTenants.includes(mtxTenant)).map( async mtxTenant => { | ||
await module.exports.addMetadata(mtxTenant, { | ||
subscribedTenantId: mtxTenant | ||
}) | ||
return mtxTenant | ||
})) | ||
} | ||
return [] | ||
} | ||
module.exports.migrate = async function migrate(tenants, options) { | ||
@@ -193,3 +209,3 @@ | ||
// add metadata in case it had not been added before | ||
await _addMetadata(tenant, metadata) | ||
await module.exports.addMetadata(tenant, metadata) | ||
} catch (error) { | ||
@@ -258,3 +274,3 @@ LOG.log('cds.xt.Extensions not yet deployed, deploying ...') | ||
if (!dry) { | ||
await _addMetadata(tenant, metadata) | ||
await module.exports.addMetadata(tenant, metadata) | ||
migrationResult.log(tenant, `Metadata for tenant ${tenant} added.`) | ||
@@ -278,3 +294,3 @@ } | ||
async function _addMetadata(tenant, metadata) { | ||
module.exports.addMetadata = async function addMetadata(tenant, metadata) { | ||
const t0 = getT0() | ||
@@ -281,0 +297,0 @@ // TODO Upsert ? |
@@ -167,8 +167,12 @@ const cds = require('@sap/cds') | ||
if (!wasOldMtx.length) { | ||
const hana = require('@sap/cds-mtxs/srv/plugins/hana/srv-mgr') | ||
try { | ||
wasOldMtx.push(!!(await hana.get('__META__'))) | ||
} catch (error) { | ||
if (error.status === 404) wasOldMtx.push(false) | ||
else throw e | ||
if (cds.env.requires.db?.kind === 'hana') { | ||
const hana = require('@sap/cds-mtxs/srv/plugins/hana/srv-mgr') | ||
try { | ||
wasOldMtx.push(!!(await hana.get('__META__'))) | ||
} catch (error) { | ||
if (error.status === 404) wasOldMtx.push(false) | ||
else throw error | ||
} | ||
} else { | ||
wasOldMtx.push(false) | ||
} | ||
@@ -175,0 +179,0 @@ } |
{ | ||
"name": "@sap/cds-mtxs", | ||
"version": "1.9.0", | ||
"version": "1.9.1", | ||
"description": "SAP Cloud Application Programming Model - Multitenancy library", | ||
@@ -5,0 +5,0 @@ "homepage": "https://cap.cloud.sap/", |
const cds = require('@sap/cds/lib') | ||
const LOG = cds.log('mtx'), DEBUG = cds.debug('mtx') | ||
const { parseHeaders, sendResult } = require('./saas-registry-util') | ||
const migration = require('../../lib/migration/migration') | ||
const DeploymentService = 'cds.xt.DeploymentService' | ||
@@ -100,15 +101,21 @@ const JobsService = 'cds.xt.JobsService' | ||
if (!one) cds.error(`Tenant ${tenant} not found`, { status: 404 }) | ||
return { tenant, ...JSON.parse(one.metadata ?? '{}') } | ||
return { subscribedTenantId: tenant, ...JSON.parse(one.metadata ?? '{}') } | ||
} | ||
return (await cds.tx({ tenant: t0 }, tx => | ||
tx.run(SELECT.from(Tenants, tenant => { tenant.ID, tenant.metadata })) | ||
)).map(({ ID, metadata }) => ({ tenant: ID, ...JSON.parse(metadata) })) | ||
)).map(({ ID, metadata }) => ({ subscribedTenantId: ID, ...JSON.parse(metadata) })) | ||
} | ||
async _getTenants() { | ||
const tenants = (await cds.tx({ tenant: t0 }, tx => | ||
tx.run(SELECT.from(Tenants, tenant => { tenant.ID })) | ||
)).map(({ ID }) => ID) | ||
const mtxTenants = await migration.getMissingMtxTenants(tenants) | ||
return [...tenants, ...mtxTenants] | ||
} | ||
async upgrade(tenantsIds, options) { | ||
if (!tenantsIds?.length) return | ||
const tenantList = tenantsIds.includes('*') ? undefined : tenantsIds | ||
const tenants = tenantList ?? (await cds.tx({ tenant: t0 }, tx => | ||
tx.run(SELECT.from(Tenants, tenant => { tenant.ID })) | ||
)).map(({ ID }) => ID) | ||
const tenants = tenantList ?? await this._getTenants() | ||
const { isSync } = parseHeaders(cds.context.http?.req.headers) | ||
@@ -115,0 +122,0 @@ const { |
@@ -5,3 +5,2 @@ const cds = require('@sap/cds/lib'), { uuid } = cds.utils | ||
const DeploymentService = 'cds.xt.DeploymentService' | ||
const Jobs = 'cds.xt.Jobs', Tasks = 'cds.xt.Tasks' | ||
@@ -8,0 +7,0 @@ |
@@ -197,8 +197,7 @@ const fs = require('fs').promises | ||
async function getExtResources(req) { | ||
const tenant = (req.user.is('internal-user') && req.data.tenant) || req.tenant | ||
if (tenant) cds.context = { tenant } | ||
const tenant = req.data.tenant || req.tenant | ||
try { | ||
async function _getExtResources(tx) { | ||
const cqn = SELECT('sources').from('cds.xt.Extensions').where('sources !=', null).orderBy('timestamp') | ||
const extSources = await cds.db.run(cqn) | ||
const extSources = await tx.run(cqn) | ||
if (extSources && extSources.length) { | ||
@@ -216,2 +215,7 @@ const root = await fs.mkdtemp(`${TEMP_DIR}${path.sep}extension-`) | ||
} | ||
} | ||
try { | ||
if (cds.context.tenant === tenant) return await _getExtResources(cds.db) | ||
else return await cds.db.tx({ tenant: tenant}, _getExtResources) | ||
} catch (e) { | ||
@@ -221,4 +225,2 @@ DEBUG?.('cds.xt.Extensions not yet deployed', e) // REVISIT: Questionable usage of try-catch pattern | ||
} | ||
return null | ||
} | ||
@@ -225,0 +227,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214976
4223