v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

+29 -1
View File
@@ -34,7 +34,7 @@ abstract class BaseApiCollection extends ResourceCollection
/**
* 컬렉션 레벨 abilities를 해석합니다.
*
* @param Request $request HTTP 요청 객체
* @param Request $request HTTP 요청 객체
* @return array<string, bool>
*/
public function resolveCollectionAbilities(Request $request): array
@@ -53,4 +53,32 @@ abstract class BaseApiCollection extends ResourceCollection
return $abilities;
}
/**
* paginator 인 경우 표준 pagination 메타를 반환합니다.
*
* 무한스크롤 화면이 전체 개수(total)와 다음 페이지 존재 여부(has_more_pages)를
* 정확히 판정할 수 있도록 노출합니다. 전체 조회(get) 등 paginator 가 아닌
* 경우에는 빈 배열을 반환하므로 toArray 에서 array_merge 로 안전하게 합칠 수 있습니다.
*
* @return array<string, mixed> ['pagination' => [...]] 또는 빈 배열
*/
protected function paginationMeta(): array
{
if (! method_exists($this->resource, 'currentPage')) {
return [];
}
return [
'pagination' => [
'current_page' => $this->resource->currentPage(),
'last_page' => $this->resource->lastPage(),
'per_page' => $this->resource->perPage(),
'total' => $this->resource->total(),
'from' => $this->resource->firstItem(),
'to' => $this->resource->lastItem(),
'has_more_pages' => $this->resource->hasMorePages(),
],
];
}
}
@@ -34,6 +34,7 @@ class ChallengeResource extends BaseApiResource
'redirect_url' => $c->redirectUrl,
'expires_at' => $c->expiresAt->toIso8601String(),
'public_payload' => $c->publicPayload,
'max_attempts' => $c->maxAttempts,
...$this->resourceMeta($request),
];
}
@@ -44,6 +44,7 @@ class ProviderResource extends BaseApiResource
'id' => $p->getId(),
'label' => $p->getLabel(),
'channels' => $p->getChannels(),
'channel_labels' => $p->getChannelLabels(),
'render_hint' => $p->getRenderHint(),
'is_available' => $p->isAvailable(),
...$this->resourceMeta($request),
@@ -0,0 +1,121 @@
<?php
namespace App\Http\Resources;
use App\Extension\Traits\ComputesLayoutContentHash;
use Illuminate\Http\Request;
/**
* 레이아웃 확장 리소스
*
* 관리자 레이아웃 편집 화면에서 사용하는 레이아웃 확장 직렬화 리소스입니다.
*/
class LayoutExtensionResource extends BaseApiResource
{
use ComputesLayoutContentHash;
/**
* 리소스를 배열로 변환
*
* @param Request $request 요청 객체
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$content = $this->getValue('content', []);
$contentJson = is_array($content) ? json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : '{}';
$extensionType = $this->getValue('extension_type');
$sourceType = $this->getValue('source_type');
return [
'id' => $this->getValue('id'),
'template_id' => $this->getValue('template_id'),
'extension_type' => $extensionType?->value ?? $extensionType,
'target_name' => $this->getValue('target_name'),
'source_type' => $sourceType?->value ?? $sourceType,
'source_identifier' => $this->getValue('source_identifier'),
'source_label' => $this->getValue('source_label', $this->getValue('source_identifier')),
'override_target' => $this->getValue('override_target'),
// 템플릿 오버라이드 여부 — index 에서 부착되며, 미부착 시 source_type 으로 폴백
'is_override' => (bool) $this->getValue(
'is_override',
($sourceType?->value ?? $sourceType) === 'template'
),
'priority' => $this->getValue('priority'),
'is_active' => (bool) $this->getValue('is_active'),
// 호스트 레이아웃 목록 — 이 확장이 주입되는 레이아웃명들.
// overlay = [target_layout], extension_point = 그 확장점을 포함하는 레이아웃 전체.
// index 에서 부착되며, 라우트 트리가 layoutName 매칭으로 화면별 연결 목록을 구성한다.
'host_layouts' => $this->getValue('host_layouts', []),
// 레이아웃 편집 페이지용 필드
'content' => $contentJson,
'size' => strlen($contentJson),
'size_formatted' => $this->formatFileSize(strlen($contentJson)),
'is_modified' => $this->resolveIsModified($content),
// 낙관적 잠금 — 다음 저장 요청에 expected_lock_version 으로 전달
'lock_version' => (int) $this->getValue('lock_version', 0),
// 현재(최신) 저장 버전 번호 — index(목록 부착)/update(저장
// 경로 transient)에서만 채워짐. 이력 없는 확장/그 외 응답은 null (배지 미표시).
'current_version' => $this->getValue('current_version') !== null
? (int) $this->getValue('current_version')
: null,
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
}
/**
* 리소스별 권한 매핑을 반환합니다.
*
* @return array<string, string>
*/
protected function abilityMap(): array
{
return [
'can_update' => 'core.templates.layouts.edit',
];
}
/**
* 관리자 수정 여부를 판단합니다.
*
* 현재 content 해시가 original_content_hash 와 다르면 수정된 것으로 간주합니다.
*
* @param array $content 현재 확장 content
* @return bool 수정 여부
*/
private function resolveIsModified(array $content): bool
{
$originalHash = $this->getValue('original_content_hash');
if (! $originalHash || empty($content)) {
return false;
}
return $this->computeContentHash($content) !== $originalHash;
}
/**
* 파일 크기를 사람이 읽기 쉬운 형태로 변환
*
* @param int $bytes 바이트 크기
* @return string 포맷된 크기 (예: "12.5 KB")
*/
private function formatFileSize(int $bytes): string
{
if ($bytes < 1024) {
return $bytes.' B';
}
if ($bytes < 1048576) {
return round($bytes / 1024, 1).' KB';
}
return round($bytes / 1048576, 1).' MB';
}
}
@@ -0,0 +1,92 @@
<?php
namespace App\Http\Resources;
use App\Models\User;
use Illuminate\Http\Request;
/**
* 레이아웃 확장 버전 리소스
*
* 레이아웃 확장의 버전 이력을 직렬화합니다.
*/
class LayoutExtensionVersionResource extends BaseApiResource
{
/**
* 리소스를 배열로 변환
*
* @param Request $request 요청 객체
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$content = $this->getValue('content', []);
$contentJson = is_array($content) ? json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : '{}';
return [
'id' => $this->getValue('id'),
'extension_id' => $this->getValue('extension_id'),
'version' => $this->getValue('version'),
'content' => $contentJson,
'changes_summary' => $this->formatChangesSummary($this->getValue('changes_summary', [])),
// 저장자 이름만 노출 (버전 히스토리 표시용 — 레이아웃 본체와 패리티
// 버전 기록). created_by ID 는 보안상 제외 유지. 관계 미로딩/탈퇴 사용자 시 null.
'created_by_name' => $this->resolveCreatorName(),
...$this->formatTimestamps(),
// created_by는 보안상 제외
...$this->resourceMeta($request),
];
}
/**
* 저장자 이름을 해석합니다.
*
* creator 관계(eager load)에서 이름만 추출합니다. 관계 미로딩 또는 탈퇴 사용자
* (created_by null)인 경우 null 을 반환합니다. created_by ID 자체는 노출하지 않습니다.
*
* @return string|null 저장자 이름 또는 null
*/
private function resolveCreatorName(): ?string
{
$creator = $this->whenLoaded('creator');
// whenLoaded 미로딩 시 MissingValue 반환 → instanceof 검사로 null 처리 (누출 방지).
return $creator instanceof User ? $creator->name : null;
}
/**
* changes_summary를 버전 목록 표시용 카운트로 노출합니다.
*
* changes_summary 는 추가/삭제 라인 수(added/removed 정수)와 문자 수 변화만 저장한다
* (라인 원문 미저장 — 적재 비대화 제거). 프론트는 added_count/removed_count
* 로 받으므로 키를 매핑한다. 구버전(라인 원문 배열을 담던 시절) 레코드는 정수가 아니라
* 배열일 수 있어 is_array 시 count() 로 보정한다. modified 는 라인 diff 에 대응 개념이
* 없어 노출하지 않는다.
*
* @param array $changesSummary 원본 changes_summary
* @return array{added_count: int, removed_count: int, char_diff: int}
*/
private function formatChangesSummary(array $changesSummary): array
{
return [
'added_count' => $this->countValue($changesSummary['added'] ?? 0),
'removed_count' => $this->countValue($changesSummary['removed'] ?? 0),
'char_diff' => $changesSummary['char_diff'] ?? 0,
];
}
/**
* changes_summary 값을 정수 카운트로 정규화합니다.
*
* 신규 구조는 정수(라인 수), 구버전 레코드는 배열(라인/경로 원문)일 수 있어 양쪽을
* 카운트로 환산한다.
*
* @param mixed $value added/removed 원본 값 (정수 또는 배열)
* @return int 라인 수
*/
private function countValue(mixed $value): int
{
return is_array($value) ? count($value) : (int) $value;
}
}
+45 -6
View File
@@ -6,20 +6,50 @@ use Illuminate\Http\Request;
class LayoutResource extends BaseApiResource
{
/**
* 레이아웃 이름 → 라우트 path 매핑 (코드 편집기 URL 동기화용).
*
* 컨트롤러가 템플릿 routes.json 으로부터 빌드해 컬렉션 전체에 주입한다.
* 라우트가 없는 레이아웃(base/partial 등)은 매핑에 없어 null 로 직렬화된다.
*
* @var array<string, string>
*/
protected array $routePathMap = [];
/**
* 레이아웃 이름 → 라우트 path 매핑을 주입합니다.
*
* @param array<string, string> $map 레이아웃 이름 → 라우트 path
* @return $this
*/
public function withRoutePathMap(array $map): static
{
$this->routePathMap = $map;
return $this;
}
/**
* 리소스를 배열로 변환
*
* @param Request $request 현재 요청 객체
* @return array<string, mixed> 직렬화 결과
*/
public function toArray(Request $request): array
{
$content = $this->getValue('content', []);
$contentJson = is_array($content) ? json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : '{}';
$name = $this->getValue('name');
return [
'id' => $this->getValue('id'),
'template_id' => $this->getValue('template_id'),
'name' => $this->getValue('name'),
'description' => $content['meta']['description'] ?? $this->getValue('name'),
'name' => $name,
'description' => $content['meta']['description'] ?? $name,
'endpoint' => $content['endpoint'] ?? null,
// 이 레이아웃을 사용하는 라우트의 path (routes.json 기준). 코드 편집기가
// 파일 선택 시 ?route= 동기화 / 위지윅에서 넘어온 ?route= 복원에 사용.
'route_path' => $this->routePathMap[$name] ?? null,
'components' => $content['components'] ?? [],
'data_sources' => $content['data_sources'] ?? [],
'metadata' => $content['metadata'] ?? [],
@@ -30,6 +60,15 @@ class LayoutResource extends BaseApiResource
'size_formatted' => $this->formatFileSize(strlen($contentJson)),
'has_update' => false, // TODO: 템플릿 파일과 DB 버전 비교 로직 추가
// 낙관적 잠금 — 다음 저장 요청에 expected_lock_version 으로 전달
'lock_version' => (int) $this->getValue('lock_version', 0),
// 현재(최신) 저장 버전 번호 — updateLayout 저장 경로에서만
// transient 로 부착됨(라우트 트리 버전 배지 동기화). 그 외 응답은 null.
'current_version' => $this->getValue('current_version') !== null
? (int) $this->getValue('current_version')
: null,
...$this->formatTimestamps(),
...$this->resourceMeta($request),
// created_by, updated_by는 보안상 제외
@@ -51,17 +90,17 @@ class LayoutResource extends BaseApiResource
/**
* 파일 크기를 사람이 읽기 쉬운 형태로 변환
*
* @param int $bytes 바이트 크기
* @param int $bytes 바이트 크기
* @return string 포맷된 크기 (예: "12.5 KB")
*/
private function formatFileSize(int $bytes): string
{
if ($bytes < 1024) {
return $bytes . ' B';
return $bytes.' B';
} elseif ($bytes < 1048576) {
return round($bytes / 1024, 1) . ' KB';
return round($bytes / 1024, 1).' KB';
} else {
return round($bytes / 1048576, 1) . ' MB';
return round($bytes / 1048576, 1).' MB';
}
}
}
+78 -11
View File
@@ -6,14 +6,39 @@ use Illuminate\Http\Request;
class LayoutVersionResource extends BaseApiResource
{
/**
* content 원본 전체를 포함할지 여부 (단건 조회 전용).
*
* 목록(versions.index)은 버전이 많아(수백 건) content 전체를 다 실으면 페이로드가
* 비대해지므로 분해된 일부 키만 노출한다. 단건 조회(showVersion)는 버전 비교 diff 가
* content 전체(slots/extends 등 분해되지 않는 키 포함)를 필요로 하므로 full_content 를
* 추가 노출한다. withFullContent() 로 opt-in.
*/
private bool $includeFullContent = false;
/**
* content 원본 전체(full_content)를 응답에 포함하도록 표시합니다 (단건 조회용).
*
* @return $this
*/
public function withFullContent(): static
{
$this->includeFullContent = true;
return $this;
}
/**
* 리소스를 배열로 변환
*
* @param Request $request 현재 요청
* @return array 버전 표시 필드 배열 (full_content 는 단건 조회 시에만 포함)
*/
public function toArray(Request $request): array
{
$content = $this->getValue('content', []);
return [
$payload = [
'id' => $this->getValue('id'),
'layout_id' => $this->getValue('layout_id'),
'version' => $this->getValue('version'),
@@ -22,29 +47,71 @@ class LayoutVersionResource extends BaseApiResource
'data_sources' => $content['data_sources'] ?? [],
'metadata' => $content['metadata'] ?? [],
'changes_summary' => $this->formatChangesSummary($this->getValue('changes_summary', [])),
// 저장자 이름만 노출 (버전 히스토리 표시용) — created_by ID 는 보안상 제외 유지.
// creator 관계 미로딩(eager load 누락)/탈퇴 사용자 시 null.
'created_by_name' => $this->resolveCreatorName(),
...$this->formatTimestamps(),
// created_by는 보안상 제외
...$this->resourceMeta($request),
];
// 단건 조회 시에만 content 원본 전체를 노출 — 버전 비교 diff 가 slots/extends 등
// 분해되지 않는 키까지 비교하려면 원본 전체가 필요하다. 목록에는 제외(비대화 회피).
if ($this->includeFullContent) {
$payload['full_content'] = is_array($content) ? $content : [];
}
return $payload;
}
/**
* changes_summary를 포맷팅하여 count 필드 추가
* 저장자 이름을 해석합니다.
*
* @param array $changesSummary 원본 changes_summary
* @return array 포맷팅된 changes_summary
* creator 관계(eager load)에서 이름만 추출합니다. 관계 미로딩 또는 탈퇴 사용자
* (created_by null)인 경우 null 을 반환합니다. created_by ID 자체는 노출하지 않습니다.
*
* @return string|null 저장자 이름 또는 null
*/
private function resolveCreatorName(): ?string
{
$creator = $this->whenLoaded('creator');
// whenLoaded 미로딩 시 MissingValue 반환 → 삼항으로 null 처리 (MissingValue 누출 방지).
return $creator instanceof \App\Models\User ? $creator->name : null;
}
/**
* changes_summary를 버전 목록 표시용 카운트로 노출합니다.
*
* changes_summary 는 추가/삭제 라인 수(added/removed 정수)와 문자 수 변화만 저장한다
* (라인 원문 미저장 — 적재 비대화 제거). 프론트는 added_count/removed_count
* 로 받으므로 키를 매핑한다. 구버전(라인 원문 배열을 담던 시절) 레코드는 정수가 아니라
* 배열일 수 있어 is_array 시 count() 로 보정한다. modified 는 라인 diff 에 대응 개념이
* 없어 노출하지 않는다.
*
* @param array $changesSummary 원본 changes_summary
* @return array{added_count: int, removed_count: int, char_diff: int}
*/
private function formatChangesSummary(array $changesSummary): array
{
return [
'added' => $changesSummary['added'] ?? [],
'removed' => $changesSummary['removed'] ?? [],
'modified' => $changesSummary['modified'] ?? [],
'added_count' => count($changesSummary['added'] ?? []),
'removed_count' => count($changesSummary['removed'] ?? []),
'modified_count' => count($changesSummary['modified'] ?? []),
'added_count' => $this->countValue($changesSummary['added'] ?? 0),
'removed_count' => $this->countValue($changesSummary['removed'] ?? 0),
'char_diff' => $changesSummary['char_diff'] ?? 0,
];
}
/**
* changes_summary 값을 정수 카운트로 정규화합니다.
*
* 신규 구조는 정수(라인 수), 구버전 레코드는 배열(라인/경로 원문)일 수 있어 양쪽을
* 카운트로 환산한다.
*
* @param mixed $value added/removed 원본 값 (정수 또는 배열)
* @return int 라인 수
*/
private function countValue(mixed $value): int
{
return is_array($value) ? count($value) : (int) $value;
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Http\Resources;
use App\Models\TemplateCustomTranslation;
use Illuminate\Http\Request;
/**
* 템플릿 커스텀 다국어 키 리소스.
*
* @property TemplateCustomTranslation $resource
*/
class TemplateCustomTranslationResource extends BaseApiResource
{
/**
* 리소스를 배열로 변환합니다.
*
* @param Request $request HTTP 요청 객체
* @return array<string, mixed> 변환된 배열 데이터
*/
public function toArray(Request $request): array
{
return [
'id' => $this->getValue('id'),
'template_id' => $this->getValue('template_id'),
'layout_name' => $this->getValue('layout_name'),
'translation_key' => $this->getValue('translation_key'),
'values' => $this->getValue('values', []),
'status' => $this->getValue('status'),
'lock_version' => (int) $this->getValue('lock_version', 0),
'created_at' => $this->getValue('created_at'),
'updated_at' => $this->getValue('updated_at'),
];
}
}
+3
View File
@@ -4,6 +4,7 @@ namespace App\Http\Resources;
use App\Contracts\Repositories\ModuleRepositoryInterface;
use App\Contracts\Repositories\PluginRepositoryInterface;
use App\Support\TemplateExternals;
use Composer\Semver\Semver;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
@@ -117,6 +118,8 @@ class TemplateResource extends BaseApiResource
'components' => $this->getValue('components', ['basic' => [], 'composite' => []]),
'license' => $this->getValue('license'),
'metadata' => $this->getValue('metadata', []),
// 외부 리소스 (template.json externals) — 정규화 책임은 TemplateExternals 에 위임
'externals' => TemplateExternals::normalize($this->getValue('externals', [])),
// 의존성 상세 정보
'dependencies' => $this->getDetailedDependencies(),
// 타임스탬프
+25 -1
View File
@@ -22,7 +22,7 @@ class UserResource extends BaseApiResource
*/
public function toArray(Request $request): array
{
return [
$data = [
'uuid' => $this->getValue('uuid'),
'name' => $this->getValue('name'),
'nickname' => $this->getValue('nickname'),
@@ -166,6 +166,30 @@ class UserResource extends BaseApiResource
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
return $data;
}
/**
* 인증 사용자(/api/auth/user, currentUser 출처) 응답용 배열을 반환합니다.
*
* 기본 toArray() 에 더해 core.user.filter_resource_data 필터를 적용해
* 모듈이 자신의 데이터(결제 통화 등)를 병합할 수 있게 한다. 프론트(_user_base.json)는
* 로그인 유저면 이 값으로 _global.preferredCurrency 를 초기화해
* "로그인 시 계정 통화로 덮어씀"(D-LOGIN-CUR)을 구조적으로 충족한다.
*
* 주의: 이 메서드는 toArray() 외부에서 수동 호출되므로 $this->when() 대신
* 삼항 연산자를 사용해야 한다. (toProfileArray/withAdminInfo 와 동일 규약)
*
* @param Request|null $request HTTP 요청
* @return array<string, mixed> 모듈 필드가 병합된 인증 사용자 데이터
*/
public function toAuthArray(?Request $request = null): array
{
$data = $this->toArray($request ?? request());
// Filter 훅: 모듈이 자신의 데이터를 응답에 병합 (toProfileArray 와 동일)
return HookManager::applyFilters('core.user.filter_resource_data', $data, $this->resource);
}
/**