chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmObjectTypeAttributesContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import { getAssetsApiBaseUrl, getJsmHeaders, resolveAssetsContext } from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsAttributesAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmObjectTypeAttributesContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
objectTypeId,
|
||||
onlyValueEditable,
|
||||
query: searchQuery,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const query = new URLSearchParams()
|
||||
if (onlyValueEditable !== undefined) {
|
||||
query.append('onlyValueEditable', String(onlyValueEditable))
|
||||
}
|
||||
if (searchQuery) query.append('query', searchQuery)
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/objecttype/${encodeURIComponent(
|
||||
objectTypeId
|
||||
)}/attributes${query.toString() ? `?${query.toString()}` : ''}`
|
||||
|
||||
const response = await fetch(url, { method: 'GET', headers: getJsmHeaders(accessToken) })
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error getting attributes', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const attributes = Array.isArray(data) ? data : (data.values ?? [])
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
attributes,
|
||||
total: attributes.length,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error getting Assets attributes', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,97 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmListObjectTypesContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import { getAssetsApiBaseUrl, getJsmHeaders, resolveAssetsContext } from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsObjectTypesAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmListObjectTypesContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
schemaId,
|
||||
excludeAbstract,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const query = new URLSearchParams()
|
||||
if (excludeAbstract !== undefined) query.append('excludeAbstract', String(excludeAbstract))
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/objectschema/${encodeURIComponent(
|
||||
schemaId
|
||||
)}/objecttypes${query.toString() ? `?${query.toString()}` : ''}`
|
||||
|
||||
const response = await fetch(url, { method: 'GET', headers: getJsmHeaders(accessToken) })
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error listing object types', {
|
||||
status: response.status,
|
||||
errorText,
|
||||
})
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const objectTypes = Array.isArray(data) ? data : (data.values ?? [])
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
objectTypes,
|
||||
total: objectTypes.length,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error listing Assets object types', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,93 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmCreateObjectContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import {
|
||||
getAssetsApiBaseUrl,
|
||||
getJsmHeaders,
|
||||
mapAssetObject,
|
||||
resolveAssetsContext,
|
||||
} from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsCreateObjectAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmCreateObjectContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
objectTypeId,
|
||||
attributes,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/object/create`
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: getJsmHeaders(accessToken),
|
||||
body: JSON.stringify({ objectTypeId, attributes }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error creating object', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: { ts: new Date().toISOString(), object: mapAssetObject(data) },
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error creating Assets object', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,81 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmDeleteObjectContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import { getAssetsApiBaseUrl, getJsmHeaders, resolveAssetsContext } from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsDeleteObjectAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmDeleteObjectContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
objectId,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/object/${encodeURIComponent(objectId)}`
|
||||
|
||||
const response = await fetch(url, { method: 'DELETE', headers: getJsmHeaders(accessToken) })
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error deleting object', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: { ts: new Date().toISOString(), objectId, deleted: true },
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error deleting Assets object', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,88 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmGetObjectContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import {
|
||||
getAssetsApiBaseUrl,
|
||||
getJsmHeaders,
|
||||
mapAssetObject,
|
||||
resolveAssetsContext,
|
||||
} from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsGetObjectAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmGetObjectContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
objectId,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/object/${encodeURIComponent(objectId)}`
|
||||
|
||||
const response = await fetch(url, { method: 'GET', headers: getJsmHeaders(accessToken) })
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error getting object', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: { ts: new Date().toISOString(), object: mapAssetObject(data) },
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error getting Assets object', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,97 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmUpdateObjectContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import {
|
||||
getAssetsApiBaseUrl,
|
||||
getJsmHeaders,
|
||||
mapAssetObject,
|
||||
resolveAssetsContext,
|
||||
} from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsUpdateObjectAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmUpdateObjectContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
objectId,
|
||||
objectTypeId,
|
||||
attributes,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/object/${encodeURIComponent(objectId)}`
|
||||
|
||||
const body: Record<string, unknown> = { attributes }
|
||||
if (objectTypeId) body.objectTypeId = objectTypeId
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: getJsmHeaders(accessToken),
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error updating object', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: { ts: new Date().toISOString(), object: mapAssetObject(data) },
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error updating Assets object', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,83 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmGetObjectSchemaContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import { getAssetsApiBaseUrl, getJsmHeaders, resolveAssetsContext } from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsSchemaAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmGetObjectSchemaContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
schemaId,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/objectschema/${encodeURIComponent(schemaId)}`
|
||||
|
||||
const response = await fetch(url, { method: 'GET', headers: getJsmHeaders(accessToken) })
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error getting schema', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: { ts: new Date().toISOString(), schema: data ?? null },
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error getting Assets schema', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,97 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmListObjectSchemasContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import { getAssetsApiBaseUrl, getJsmHeaders, resolveAssetsContext } from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsSchemasAPI')
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmListObjectSchemasContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
startAt,
|
||||
maxResults,
|
||||
includeCounts,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const query = new URLSearchParams()
|
||||
if (startAt !== undefined) query.append('startAt', String(startAt))
|
||||
if (maxResults !== undefined) query.append('maxResults', String(maxResults))
|
||||
if (includeCounts !== undefined) query.append('includeCounts', String(includeCounts))
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/objectschema/list${
|
||||
query.toString() ? `?${query.toString()}` : ''
|
||||
}`
|
||||
|
||||
const response = await fetch(url, { method: 'GET', headers: getJsmHeaders(accessToken) })
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error listing schemas', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
schemas: data.values ?? [],
|
||||
total: data.total ?? (data.values?.length || 0),
|
||||
isLast: data.isLast ?? data.last ?? true,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error listing Assets schemas', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,122 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { getErrorMessage, toError } from '@sim/utils/errors'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { jsmSearchObjectsAqlContract } from '@/lib/api/contracts/selectors/jsm'
|
||||
import { parseRequest } from '@/lib/api/server'
|
||||
import { checkInternalAuth } from '@/lib/auth/hybrid'
|
||||
import {
|
||||
validateAssetsWorkspaceId,
|
||||
validateJiraCloudId,
|
||||
} from '@/lib/core/security/input-validation'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { parseAtlassianErrorMessage } from '@/tools/jira/utils'
|
||||
import {
|
||||
getAssetsApiBaseUrl,
|
||||
getJsmHeaders,
|
||||
mapAssetObject,
|
||||
resolveAssetsContext,
|
||||
} from '@/tools/jsm/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const logger = createLogger('JsmAssetsSearchAPI')
|
||||
|
||||
/** Coerce a string|number|boolean param into a number, falling back when unset */
|
||||
function toNumber(value: string | number | undefined, fallback: number): number {
|
||||
if (value === undefined) return fallback
|
||||
const parsed = typeof value === 'number' ? value : Number(value)
|
||||
return Number.isFinite(parsed) ? parsed : fallback
|
||||
}
|
||||
|
||||
export const POST = withRouteHandler(async (request: NextRequest) => {
|
||||
const auth = await checkInternalAuth(request)
|
||||
if (!auth.success || !auth.userId) {
|
||||
return NextResponse.json({ error: auth.error || 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = await parseRequest(jsmSearchObjectsAqlContract, request, {})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const {
|
||||
domain,
|
||||
accessToken,
|
||||
cloudId: cloudIdParam,
|
||||
workspaceId: workspaceIdParam,
|
||||
qlQuery,
|
||||
page,
|
||||
resultsPerPage,
|
||||
includeAttributes,
|
||||
objectTypeId,
|
||||
objectSchemaId,
|
||||
} = parsed.data.body
|
||||
|
||||
const { cloudId, workspaceId } = await resolveAssetsContext(
|
||||
domain,
|
||||
accessToken,
|
||||
cloudIdParam,
|
||||
workspaceIdParam
|
||||
)
|
||||
|
||||
const cloudIdValidation = validateJiraCloudId(cloudId, 'cloudId')
|
||||
if (!cloudIdValidation.isValid) {
|
||||
return NextResponse.json({ error: cloudIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const workspaceIdValidation = validateAssetsWorkspaceId(workspaceId, 'workspaceId')
|
||||
if (!workspaceIdValidation.isValid) {
|
||||
return NextResponse.json({ error: workspaceIdValidation.error }, { status: 400 })
|
||||
}
|
||||
|
||||
const includeAttrs =
|
||||
includeAttributes === undefined ? true : String(includeAttributes) === 'true'
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
qlQuery,
|
||||
page: toNumber(page, 1),
|
||||
resultsPerPage: toNumber(resultsPerPage, 25),
|
||||
includeAttributes: includeAttrs,
|
||||
}
|
||||
if (objectTypeId) body.objectTypeId = objectTypeId
|
||||
if (objectSchemaId) body.objectSchemaId = objectSchemaId
|
||||
|
||||
const url = `${getAssetsApiBaseUrl(cloudId, workspaceId)}/object/aql`
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: getJsmHeaders(accessToken),
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
logger.error('Assets API error running AQL search', { status: response.status, errorText })
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: parseAtlassianErrorMessage(response.status, response.statusText, errorText),
|
||||
details: errorText,
|
||||
},
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
output: {
|
||||
ts: new Date().toISOString(),
|
||||
objects: Array.isArray(data.objectEntries) ? data.objectEntries.map(mapAssetObject) : [],
|
||||
total: data.totalFilterCount ?? (data.objectEntries?.length || 0),
|
||||
pageNumber: data.pageNumber ?? 1,
|
||||
pageSize: data.pageSize ?? (data.objectEntries?.length || 0),
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Error running Assets AQL search', { error: toError(error).message })
|
||||
return NextResponse.json(
|
||||
{ error: getErrorMessage(error, 'Internal server error'), success: false },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user