---
# System prepended metadata

title: 2024-01-15 MABS-RI+ Sequence Diagram

---

# 2024-01-15 MABS-RI+ Sequence Diagram

# 1. Create Campaign & SSO

## Pseudo Flow

- Use Form POST with jwtToken in PostBody

- MerchantAdvBooking System -- Form POST: `/user/transfer` with Body: `{"token": ${jwt}}` --> Radica System

- Details: refer to the SSO Diagram

- Transfer Endpoint API Stub: Provided by Radica Dev Team

## JWT Spec

### Header

```json
{
  "alg": "RS256",
  "typ": "JWT"
}
```

### Payload

```jsonc
{
  "iss": "hktv-edms",
  "sub": "edms-ri-sso",
  "username": "mabs-merchant-user", // Created by RI+ User API
  "iat": ${now_time},
  "exp": ${now_time + 120s}, // 120 sec expired
}
```
- Need to put campaign id in order to open the campaign page after login?

### JWT Example

- Keys: (HKTV-EDM owned the private key)
- *RSA Public key should be given in offline at this moment*
    - May consider to use jwks endpoint in the future

```
-----BEGIN RSA PRIVATE KEY-----
MIIG5AIBAAKCAYEA5AlZOzY2vfohM/k2ubdQiiSC1lZVPJdS1RkmgqLRemChXy/o
X2Sys1Yfne0mbtGrdMADMWghITHUErjXgtOM1kAIjQ/mc3+Pj4REWW7wHxoJUvGj
eLn1bxr4YOg0kCfE2cy4O6lE+5KYB220CEjg921Wb9TbWb3eJg69dp7SHRszlOhy
oewbtiqv3CCLRKyj0n1mmw14SttaqW6y43ttxzHYDAmxeCxLxcTU8m6u+dpa1QFO
rDU4tUreB8zFmHuTINqGBhuUghwtTET/cFtXNuJj2jO0a+HL7/7Iz6C7Xjhy01GG
BRCRdxqZ+6PLrGzv1/wJFnKOhaCr3s8ouYLpIXQ9YR1qvr2tJHG5HO1YS5bqSiDm
WU9tUMI6kkzh/y5QaQJ9NP3pH+lrb5JxmDzz63lWzBmiRljsRM4HQs247Xw02oMG
REKwt1V/OctMcu1vW1iSA6458oGK0cKLf0f0dDmW5+F1bYaB1ehQxZAdf/bgPB1e
lg6NEKl+EKLOZVBbAgMBAAECggGBAK5I+tsHh3VRfBkGCy6MDdFXMGxy1Xi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fEqSsilenX0GozDNJHFFoFNTViPCPb0Dyx1CSy2YxYCIDlO8NOaq6bb3RIXAYxLkWaqQu9J5DVoWXuf9YWzwNDXM4TQm6cuuWAcKR2ML20ot4WGziKhY4Ab85UdwCrSMgE2tps2Bs0bZzHxCtIyiVT5eWzpDW9j5qCnawpNhAvbpaGMjhvi1tcWuThs268eub7vHDpKfDPsNmBR74aJYSA4qu_R6s2KFJJzBg7PuKp0qoVnjq9I-ifC9VNXVQfq5ltx_9-gh7sUDugELAZpJJWXgOytJNH2XG2gE5Nk-hBNYAUPzGRvXc8U1qPzp-VtTOFdsnoTFQiOwejk8YGZ-M0Xf2pHVGZ92Ane0s_CvbgpyXso5I3ghXyLl3MqDppXUTnQTSJjf-stNqq5d_vp_0BsSeOPMEqFj_Gei1OwFcdfmnERpWVijP5R5MVQ9d1yNfED8NLHA_mQML
```

## Flow Diagram (Merchant: Create User & SSO Login)

```mermaid
sequenceDiagram
    box green HKTV
    participant HKTV-MABS Web
    participant HKTV-MABS
    participant HKTV-EDM
    end
    box blue Radica
    participant RADICA-RI
    participant RADICA-RI Web
    end
    
    rect rgb(100,100,100)
        note right of HKTV-MABS Web: Create a EDM Booking
        HKTV-MABS Web ->> HKTV-MABS: Create EDM Booking
        HKTV-MABS ->>+ HKTV-EDM: Request Create Campaign <br/> by User & StoreCode & RefId
        note over HKTV-EDM: Check if Radica Division exists for Store
        alt is Division NotExist
            HKTV-EDM ->>+ RADICA-RI: Create Division
            RADICA-RI ->>- HKTV-EDM: Return Division
        end
        note over HKTV-EDM: Check if Radica User Account exists for Merchant
        alt is User NotExist
            HKTV-EDM ->>+ RADICA-RI: Create User
            RADICA-RI ->>- HKTV-EDM: Return User
        end
        note over HKTV-EDM: Check if Radica User Account is Under Division
        alt is User NotUnderDivision
            HKTV-EDM ->>+ RADICA-RI: Update User Division
            RADICA-RI ->>- HKTV-EDM: Return User
        end
        HKTV-EDM ->>+ RADICA-RI: Create Campaign <br/> by (Division=StoreCode & RefId)
        RADICA-RI ->>- HKTV-EDM: Return CampaignId
        note left of HKTV-EDM: Store CampaignInfo By StoreCode & RefId
        HKTV-EDM ->>- HKTV-MABS: Return booking success
        HKTV-MABS ->> HKTV-MABS Web: Display Button for Editing / Viewing Campaign in Radica
    end

    rect rgb(0,100,100)
        note right of HKTV-MABS Web: SSO to RI+ Web
        HKTV-MABS Web ->>+ HKTV-MABS: Press create EDM Template Button <br/> or View Ad Job Status
        HKTV-MABS ->>+ HKTV-EDM: Request JWT Token to access RI+ (User + RefId)
        HKTV-EDM ->>- HKTV-MABS: Return JWT
        HKTV-MABS ->>- HKTV-MABS Web: Return JWT to Client
        HKTV-MABS Web ->>+ RADICA-RI Web: POST: /user/transfer  Body: {token: ${jwt}}
        RADICA-RI Web ->>+ RADICA-RI: Verify Token Signature
        RADICA-RI ->>- RADICA-RI Web: Return User Info & User Session
        note left of RADICA-RI Web: Merchant create their own EDM Template <br/> or View Campaign Status
    end
```

# 2. Admin SSO

## Sequence Diagram

```mermaid
sequenceDiagram
    box green HKTV
    participant HKTV-MABS Web
    participant HKTV-MABS
    participant HKTV-EDM
    end
    box blue Radica
    participant RADICA-RI
    participant RADICA-RI Web
    end
    
    rect rgb(100,100,100)
        note right of HKTV-MABS Web: Admin Login
        HKTV-MABS Web->>+HKTV-MABS: Admin clicks SSO
        HKTV-MABS->>+HKTV-EDM: Request JWT Token to access RI+ <br/> (User)
        note over HKTV-EDM: Check if User Account exists for Admin
        alt is User NotExist
            HKTV-EDM ->>+ RADICA-RI: Create User (is_all_division=true)
            RADICA-RI ->>- HKTV-EDM: Return User
        end
        HKTV-EDM ->>- HKTV-MABS: Return JWT
        HKTV-MABS ->>- HKTV-MABS Web: Return JWT to Client
        HKTV-MABS Web ->>+ RADICA-RI Web: POST: /user/transfer  Body: {token: ${jwt}}
        RADICA-RI Web ->>+ RADICA-RI: Verify Token Signature
        RADICA-RI ->>- RADICA-RI Web: Return User Info & User Session
        note left of RADICA-RI Web: Admin Approve EDM Campaigns <br/> or View Campaign Status
    end
```

# 3. Sync email list (i.e. customer group)

## Sequence Diagram

```mermaid
sequenceDiagram
    box green HKTV
    participant HKTV-EDM
    participant HKTV-datalake
    end
    box blue Radica
    participant RADICA-RI
    end
    
    rect rgb(100,100,100)
        note right of HKTV-EDM: Get Email list
        HKTV-EDM->>+HKTV-datalake: Request email list by customer group table_uuid
        HKTV-datalake->>-HKTV-EDM: Return email list by RabbitMQ <br/> (excluded opt-out emails)
        HKTV-EDM->>+RADICA-RI: POST contact list
    end
```