Initial commit

This commit is contained in:
Yaser
2026-08-13 19:56:46 +03:30
commit de1d57a67b
474 changed files with 43185 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
# frozen_string_literal: true
module API::V2
module Entities
class Activity < API::V2::Entities::Base
expose :id,
documentation: {
type: 'Integer',
desc: 'Activity ID'
}
expose :user_ip,
documentation: {
type: 'String',
desc: 'User IP'
}
expose :user_agent,
documentation: {
type: 'String',
desc: 'User Browser Agent'
}
expose :topic,
documentation: {
type: 'String',
desc: 'Defined topic (session, adjustments) or general by default'
}
expose :action,
documentation: {
type: 'String',
desc: "API action: POST => 'create', PUT => 'update', GET => 'read', DELETE => 'delete', PATCH => 'update' or system if there is no match of HTTP method"
}
expose :result,
documentation: {
type: 'String',
desc: 'Status of API response: succeed, failed, denied'
}
expose :data,
documentation: {
type: 'String',
desc: 'Parameters which was sent to specific API endpoint'
}
with_options(format_with: :iso_timestamp) do
expose :created_at
end
end
end
end

View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true
module API::V2
module Entities
class AdminLabelView < API::V2::Entities::Base
expose :key,
documentation: {
type: 'String',
desc: 'Label key. [a-z0-9_-]+ should be used. Min - 3, max - 255 characters.'
}
expose :value,
documentation: {
type: 'String',
desc: 'Label value. [A-Za-z0-9_-] should be used. Min - 3, max - 255 characters.'
}
expose :scope,
documentation: {
type: 'String',
desc: "Label scope: 'public' or 'private'"
}
expose :description,
documentation: {
type: 'String',
desc: "Label desc: json string with any additional information"
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,43 @@
# frozen_string_literal: true
module API::V2
module Entities
class APIKey < API::V2::Entities::Base
expose :kid,
documentation: {
type: 'String',
desc: 'JWT public key'
}
expose :algorithm,
documentation: {
type: 'String',
desc: 'Cryptographic hash function type'
}
expose :scope,
documentation: {
type: 'String',
desc: 'Serialized array of scopes'
}
expose :state,
documentation: {
type: 'String',
desc: 'active/non-active state of key'
}
expose :secret,
documentation: {
type: 'String',
desc: 'Api key secret'
},
if: ->(api_key) { api_key.hmac? }
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,12 @@
# encoding: UTF-8
# frozen_string_literal: true
module API
module V2
module Entities
class Base < Grape::Entity
format_with(:iso_timestamp) { |t| t.iso8601 if t }
end
end
end
end

View File

@@ -0,0 +1,39 @@
# frozen_string_literal: true
module API
module V2
module Entities
# comment retrieval entity
class Comment < API::V2::Entities::Base
expose :id,
documentation: {
type: 'Integer',
desc: 'Comment id'
}
expose :author_uid,
documentation: {
type: 'String',
desc: 'Comment author UID'
}
expose :title,
documentation: {
type: 'String',
desc: 'Comment title'
}
expose :data,
documentation: {
type: 'String',
desc: 'Comment plain text'
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end
end

View File

@@ -0,0 +1,27 @@
# frozen_string_literal: true
module API
module V2
module Entities
# data storage retrieval entity
class DataStorage < API::V2::Entities::Base
expose :title,
documentation: {
type: 'String',
desc: 'Any additional data title'
}
expose :data,
documentation: {
type: 'String',
desc: 'Any additional data json key:value pairs'
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end
end

View File

@@ -0,0 +1,55 @@
# frozen_string_literal: true
module API
module V2
module Entities
# Return user document with related info
class Document < API::V2::Entities::Base
expose :upload,
documentation: {
type: 'String',
desc: 'File Upload'
}
expose :url,
documentation: {
type: 'String',
desc: 'File url'
} do |document|
document&.upload&.url
end
expose :doc_type,
documentation: {
type: 'String',
desc: 'Document type: passport, driver license, utility bill, identity card, institutional, address, residental'
}
expose :doc_number,
documentation: {
type: 'String',
desc: 'Submasked document number: AB123123 type'
} do |document|
Barong::App.config.api_data_masking_enabled ? document.sub_masked_doc_number : document.doc_number
end
expose :doc_expire,
documentation: {
type: 'String',
desc: 'Expire date of uploaded documents'
}
expose :metadata,
documentation: {
type: 'String',
desc: 'Any additional stored data'
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end
end

View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
module API::V2
module Entities
class Label < API::V2::Entities::Base
expose :key,
documentation: {
type: 'String',
desc: 'Label key. [a-z0-9_-]+ should be used. Min - 3, max - 255 characters.'
}
expose :value,
documentation: {
type: 'String',
desc: 'Label value. [A-Za-z0-9_-] should be used. Min - 3, max - 255 characters.'
}
expose :scope,
documentation: {
type: 'String',
desc: "Label scope: 'public' or 'private'"
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,27 @@
# frozen_string_literal: true
module API
module V2
module Entities
class Level < API::V2::Entities::Base
expose :id,
documentation: {
type: 'Integer',
desc: 'Level identifier, level number'
}
expose :key,
documentation: {
type: 'String',
desc: 'Label key. [A-Za-z0-9_-] should be used. Min - 3, max - 255 characters.'
}
expose :value,
documentation: {
type: 'String',
desc: 'Label value. [A-Za-z0-9_-] should be used. Min - 3, max - 255 characters.'
}
end
end
end
end

View File

@@ -0,0 +1,50 @@
# frozen_string_literal: true
module API
module V2
module Entities
class Permission < API::V2::Entities::Base
expose :id,
documentation: {
type: 'Integer',
desc: 'Permission id'
}
expose :action,
documentation: {
type: 'String',
desc: 'Permission action: accept (allow access (drop access), audit (record activity)'
}
expose :role,
documentation: {
type: 'String',
desc: 'Permission user role'
}
expose :verb,
documentation: {
type: 'String',
desc: 'Permission verb: put, post, delete, get'
}
expose :path,
documentation: {
type: 'String',
desc: 'API path'
}
expose :topic,
documentation: {
type: 'String',
desc: 'Permission topic: general, session etc'
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end
end

View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
module API
module V2
module Entities
# Phone request response
class Phone < API::V2::Entities::Base
expose :country,
documentation: {
type: 'String',
desc: 'Phone country'
}
expose :number,
documentation: {
type: 'String',
desc: 'Submasked phone number'
} do |phone|
Barong::App.config.api_data_masking_enabled ? phone.sub_masked_number : phone.number
end
expose :validated_at,
documentation: {
type: 'Datetime',
desc: 'Phone validation date'
}
end
end
end
end

View File

@@ -0,0 +1,85 @@
# frozen_string_literal: true
module API::V2
module Entities
class Profile < API::V2::Entities::Base
expose :first_name,
documentation: {
type: 'String',
desc: 'First Name'
}
expose :last_name,
documentation: {
type: 'String',
desc: 'Submasked last name'
} do |profile|
Barong::App.config.api_data_masking_enabled ? profile.sub_masked_last_name : profile.last_name
end
expose :national_code,
documentation: {
type: 'String',
desc: 'Submasked national code'
} do |profile|
Barong::App.config.api_data_masking_enabled ? profile.sub_masked_national_code : profile.national_code
end
expose :dob,
documentation: {
type: 'Date',
desc: 'Submasked birth date'
} do |profile|
Barong::App.config.api_data_masking_enabled ? profile.sub_masked_dob : profile.dob
end
expose :address,
documentation: {
type: 'String',
desc: 'Address'
}
expose :postcode,
documentation: {
type: 'String',
desc: 'Address Postcode'
}
expose :city,
documentation: {
type: 'String',
desc: 'City name'
}
expose :country,
documentation: {
type: 'String',
desc: 'Country name'
}
expose :state,
documentation: {
type: 'String',
desc: 'Profile state: drafted, submitted, verified, rejected'
}
expose :metadata,
documentation: {
type: 'Hash',
desc: 'Profile additional fields'
}
expose :upload,
documentation: {
type: 'String',
desc: 'Address Postcode'
} do |profile|
end
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,48 @@
# frozen_string_literal: true
module API::V2
module Entities
class Restriction < API::V2::Entities::Base
expose :id,
documentation: {
type: 'Integer',
desc: 'Restriction id'
}
expose :category,
documentation: {
type: 'String',
desc: 'Restriction categories: blacklist, maintenance, whitelist, blocklogin'
}
expose :scope,
documentation: {
type: 'String',
desc: 'Restriction scopes: continent, country, ip, ip_subnet, all'
}
expose :value,
documentation: {
type: 'String',
desc: 'Restriction value: IP address, country abbreviation, all'
}
expose :code,
documentation: {
type: 'Integer',
desc: "Restriction codes: #{::Restriction::DEFAULT_CODES}"
}
expose :state,
documentation: {
type: 'String',
desc: 'Restriction states: disabled, enabled'
}
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,44 @@
# frozen_string_literal: true
module API::V2
module Entities
class ServiceAccounts < API::V2::Entities::Base
expose :email,
documentation: {
type: 'String',
desc: 'User Email'
}
expose :uid,
documentation: {
type: 'String',
desc: 'User UID'
}
expose :role,
documentation: {
type: 'String',
desc: 'Service Account Role'
}
expose :level,
documentation: {
type: 'Integer',
desc: 'User Level'
}
expose :state,
documentation: {
type: 'String',
desc: 'Service Account State: active, disabled'
}
expose :user, using: Entities::User
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,44 @@
# frozen_string_literal: true
module API::V2
module Entities
class Treasury < API::V2::Entities::Base
expose :id,
documentation: {
type: 'Integer',
desc: 'id of record'
}
expose :title,
documentation: {
type: 'String',
desc: 'title'
}
expose :state,
documentation: {
type: 'String',
desc: 'state'
}
expose :kind,
documentation: {
type: 'String',
desc: 'kind'
}
expose :data,
documentation: {
type: 'String',
desc: 'Submasked data'
} do |treasury|
Barong::App.config.api_data_masking_enabled ? treasury.sub_masked_data : treasury.data
end
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end

View File

@@ -0,0 +1,60 @@
# frozen_string_literal: true
module API
module V2
module Entities
# Basic user info
class User < API::V2::Entities::Base
expose :email,
documentation: {
type: 'String',
desc: 'User Email'
}
expose :uid,
documentation: {
type: 'String',
desc: 'User UID'
}
expose :role,
documentation: {
type: 'String',
desc: 'User role'
}
expose :level,
documentation: {
type: 'Integer',
desc: 'User level'
}
expose :otp,
documentation: {
type: 'Boolean',
desc: 'is 2FA enabled for account'
}
expose :state,
documentation: {
type: 'String',
desc: 'User state: active, pending, inactive'
}
expose :referral_uid,
documentation: {
type: 'String',
desc: 'UID of referrer'
} do |user|
user.referral_uid
end
expose :data,
documentation: {
type: 'String',
desc: 'Additional phone and profile info'
}
end
end
end
end

View File

@@ -0,0 +1,80 @@
# frozen_string_literal: true
module API
module V2
module Entities
# User information containing profile, labels and documents
class UserWithFullInfo < API::V2::Entities::Base
expose :email,
documentation: {
type: 'String',
desc: 'User Email'
}
expose :uid,
documentation: {
type: 'String',
desc: 'User UID'
}
expose :role,
documentation: {
type: 'String',
desc: 'User role'
}
expose :level,
documentation: {
type: 'Integer',
desc: 'User level'
}
expose :otp,
documentation: {
type: 'Boolean',
desc: 'is 2FA enabled for account'
}
expose :state,
documentation: {
type: 'String',
desc: 'User state: active, pending, inactive'
}
expose :referral_uid,
documentation: {
type: 'String',
desc: 'UID of referrer'
} do |user|
user.referral_uid
end
expose :data,
documentation: {
type: 'String',
desc: 'Additional phone and profile info'
}
expose :csrf_token,
documentation: {
type: 'String',
desc: 'Сsrf protection token'
},
if: ->(_, options) { options[:csrf_token] } do |_user, options|
options[:csrf_token]
end
expose :labels, using: Entities::Label
expose :phones, using: Entities::Phone
expose :profiles, using: Entities::Profile
expose :data_storages, using: Entities::DataStorage
# activities, as sensitive and potentialy too big data should be queried separately
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end
end

View File

@@ -0,0 +1,74 @@
# frozen_string_literal: true
module API
module V2
module Entities
# User information containing profile, labels and documents
class UserWithKYC < API::V2::Entities::Base
expose :email,
documentation: {
type: 'String',
desc: 'User Email'
}
expose :uid,
documentation: {
type: 'String',
desc: 'User UID'
}
expose :role,
documentation: {
type: 'String',
desc: 'User role'
}
expose :level,
documentation: {
type: 'Integer',
desc: 'User level'
}
expose :otp,
documentation: {
type: 'Boolean',
desc: 'is 2FA enabled for account'
}
expose :state,
documentation: {
type: 'String',
desc: 'User state: active, pending, inactive'
}
expose :referral_uid,
documentation: {
type: 'String',
desc: 'UID of referrer'
} do |user|
user.referral_uid
end
expose :data,
documentation: {
type: 'String',
desc: 'Additional phone and profile info'
}
expose :profiles, using: Entities::Profile
expose :labels, using: Entities::AdminLabelView
# expose :phones, using: Entities::Phone
# expose :documents, using: Entities::Document
# expose :data_storages, using: Entities::DataStorage
# expose :comments, using: Entities::Comment
# activities, as sensitive and potentialy too big data should be queried separately
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end
end

View File

@@ -0,0 +1,64 @@
# frozen_string_literal: true
module API::V2
module Entities
class UserWithProfile < API::V2::Entities::Base
expose :email,
documentation: {
type: 'String',
desc: 'User Email'
}
expose :uid,
documentation: {
type: 'String',
desc: 'User UID'
}
expose :role,
documentation: {
type: 'String',
desc: 'User role'
}
expose :level,
documentation: {
type: 'Integer',
desc: 'User level'
}
expose :otp,
documentation: {
type: 'Boolean',
desc: 'is 2FA enabled for account'
}
expose :state,
documentation: {
type: 'String',
desc: 'User state: active, pending, inactive'
}
expose :referral_uid,
documentation: {
type: 'String',
desc: 'UID of referrer'
} do |user|
user.referral_uid
end
expose :data,
documentation: {
type: 'String',
desc: 'Additional phone and profile info'
}
expose :profiles, using: Entities::Profile
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end