Allmine API

Legal documents overview — RTK Query migration

~5 dkMobil / WebKararlı

Legal overview ve zorunlu doküman kuralları mobil

React Native RTK Query Migration - Legal Overview

Migration rehberi

Yapılandırma sırası için Migration şablonu. Yeni düzenlemelerde Amaç → Önkoşullar → Endpoint → Request/Response → Hata kodları → Client adımları → İlgili sayfalar bölümlerini tercih edin.

Bu doküman, legal-documents/overview tarafında yapılan yeni migration için React Native + RTK Query entegrasyonunda yapılması gereken değişiklikleri anlatır.

1) Neden bu migration?

Backend tarafında legal overview mantigi güncellendi:

  • payment_terms ve purchase_terms artık onboarding core alanlarini overwrite etmez.
  • Overview cevabina additionalDocuments alani eklendi.
  • Dokumanlarin zorunluluk durumu artık yonetilebilir:
    • Dokuman modelinde isRequiredInOverview var.
    • Overview item seviyesinde isRequired donuyor.
  • requiredDocuments, allConsentsGiven, needsConsent sadece isRequired === true olan dokümanlara gore hesaplanır.

Bu değişiklik, mobil tarafta "tüm legal dokümanlar zorunlu" algısını kaldırmak için gereklidir.

2) Backend contract ozeti

Yeni/degisen alanlar:

  • privacyPolicy (core)
  • termsOfUse (core)
  • consentForm (core)
  • additionalDocuments: DocumentOverviewDetail[] (yeni)
  • requiredDocuments: DocumentType[]
  • allConsentsGiven: boolean
  • needsConsent: boolean
  • currentVersions: Partial<Record<DocumentType, string>>

DocumentOverviewDetail:

  • type
  • title
  • version
  • hasUserConsented
  • userConsentDate
  • needsUpdate
  • isRequired

Legal document item response artık:

  • isRequiredInOverview: boolean alanini da icerir.

Not:

  • Onboarding step-7 backend dogrulamasi bu migrationda degismedi.
  • Step-7 halen privacyPolicy, termsOfUse, consentForm payload yapisiyla calisir.

3) Mobil type değişiklikleri

Ornek type seti:

export type DocumentType =
  | 'privacy_policy'
  | 'terms_of_use'
  | 'consent_form'
  | 'payment_terms'
  | 'purchase_terms';

export type DocumentOverviewDetail = {
  type: DocumentType;
  title: string;
  version: string;
  hasUserConsented: boolean;
  userConsentDate?: string;
  needsUpdate: boolean;
  isRequired: boolean;
};

export type LegalOverviewResponse = {
  privacyPolicy: DocumentOverviewDetail;
  termsOfUse: DocumentOverviewDetail;
  consentForm: DocumentOverviewDetail;
  additionalDocuments: DocumentOverviewDetail[];
  allConsentsGiven: boolean;
  needsConsent: boolean;
  requiredDocuments: DocumentType[];
  currentVersions: Partial<Record<DocumentType, string>>;
};

export type ActiveLegalDocument = {
  _id: string;
  type: DocumentType;
  version: string;
  title: string;
  content: string;
  language: string;
  isActive: boolean;
  isRequiredInOverview: boolean;
  effectiveDate?: string;
  createdAt?: string;
  updatedAt?: string;
};

4) RTK Query endpoint guncellemeleri

Ornek API slice:

import { baseApi } from './baseApi';

type BaseResponseDto<T> = {
  isSuccess: boolean;
  statusCode: number;
  data: T;
  errors?: string[];
  timestamp: string;
};

const unwrap = <T>(response: BaseResponseDto<T> | T): T => {
  if (response && typeof response === 'object' && 'data' in (response as any)) {
    return (response as BaseResponseDto<T>).data;
  }
  return response as T;
};

export const legalDocumentsApi = baseApi.injectEndpoints({
  endpoints: (builder) => ({
    getLegalOverview: builder.query<LegalOverviewResponse, void>({
      query: () => ({ url: '/legal-documents/overview' }),
      transformResponse: (response: BaseResponseDto<LegalOverviewResponse> | LegalOverviewResponse) => {
        const data = unwrap(response);
        return {
          ...data,
          additionalDocuments: data.additionalDocuments ?? [],
        };
      },
      providesTags: [{ type: 'LegalDocuments', id: 'OVERVIEW' }],
    }),

    getActiveLegalDocuments: builder.query<ActiveLegalDocument[], { language?: string } | void>({
      query: (params) => ({
        url: '/legal-documents/active',
        params,
      }),
      transformResponse: (response: BaseResponseDto<ActiveLegalDocument[]> | ActiveLegalDocument[]) => {
        const data = unwrap(response);
        return data.map((doc) => ({
          ...doc,
          isRequiredInOverview: typeof doc.isRequiredInOverview === 'boolean'
            ? doc.isRequiredInOverview
            : ['privacy_policy', 'terms_of_use', 'consent_form'].includes(doc.type),
        }));
      },
      providesTags: [{ type: 'LegalDocuments', id: 'ACTIVE' }],
    }),
  }),
});

5) UI veri akisi değişiklikleri

Onerilen mantik:

  1. getLegalOverview ile core + additional dokümanları çek.
  2. UI listesi:
    • Core: privacyPolicy, termsOfUse, consentForm
    • Additional: additionalDocuments
  3. Dokuman rozetleri:
    • isRequired === true -> "Zorunlu"
    • isRequired === false -> "Opsiyonel"
  4. CTA / tamamlanma kontrolu:
    • Overview bazli zorunluluk için requiredDocuments kullan.
    • Onboarding step-7 payloadinda yalnızcaca core 3 alan gönder.

6) Step-7 ile uyumluluk notu (kritik)

Bu migrationda backend step-7 dogrulamasi degismedigi için:

  • POST /onboarding/step-7 payloadi ayni kalmali:
    • privacyPolicy
    • termsOfUse
    • consentForm
  • additionalDocuments step-7 payloadina eklenmemeli.

Opsiyonel/ek doküman consent kaydi gerektiginde POST /legal-documents/consent endpointi ayrica kullanilabilir.

7) Backward compatibility fallback kurallari

Gecis suresince eski backend response gelebilir. Mobilde fallback ekleyin:

  • additionalDocuments yoksa: []
  • isRequiredInOverview yoksa:
    • privacy_policy, terms_of_use, consent_form -> true
    • payment_terms, purchase_terms -> false

Bu fallback, kademeli deploy surecinde ekran kirilmasini onler.

8) Test checklist (mobil)

En az su senaryolari test edin:

  1. Core 3 doküman zorunlu, additional dokümanlar opsiyonel görünüyor.
  2. consentForm karti artık payment/purchase ile karismiyor.
  3. requiredDocuments sadece gerekli doküman tiplerini iceriyor.
  4. allConsentsGiven ve needsConsent degerleri UI durumuyla tutarli.
  5. Eski response simulasyonunda (additionalDocuments absent) fallback dogru calisiyor.
  6. Step-7 submit hala sadece 3 core consent ile basarili.

9) Rollout sirasi (onerilen)

  1. Mobil type + RTK Query transform/fallback kodunu ekle.
  2. UI'da additionalDocuments render et ve required rozetini isRequired ile belirle.
  3. QA checklist ile dogrula.
  4. Ardindan production release.

On this page