diff --git a/packages/albus-sdk/src/countries.ts b/packages/albus-sdk/src/countries.ts new file mode 100644 index 00000000..13b00c1f --- /dev/null +++ b/packages/albus-sdk/src/countries.ts @@ -0,0 +1,1502 @@ +export const COUNTRIES_LIST = [ + { + id: 1, + name: 'Afghanistan', + code2: 'AF', + code3: 'AFG' + }, + { + id: 2, + name: 'Albania', + code2: 'AL', + code3: 'ALB' + }, + { + id: 3, + name: 'Algeria', + code2: 'DZ', + code3: 'DZA' + }, + { + id: 4, + name: 'American Samoa', + code2: 'AS', + code3: 'ASM' + }, + { + id: 5, + name: 'Andorra', + code2: 'AD', + code3: 'AND' + }, + { + id: 6, + name: 'Angola', + code2: 'AO', + code3: 'AGO' + }, + { + id: 7, + name: 'Anguilla', + code2: 'AI', + code3: 'AIA' + }, + { + id: 8, + name: 'Antarctica', + code2: 'AQ', + code3: 'ATA' + }, + { + id: 9, + name: 'Antigua and Barbuda', + code2: 'AG', + code3: 'ATG' + }, + { + id: 10, + name: 'Argentina', + code2: 'AR', + code3: 'ARG' + }, + { + id: 11, + name: 'Armenia', + code2: 'AM', + code3: 'ARM' + }, + { + id: 12, + name: 'Aruba', + code2: 'AW', + code3: 'ABW' + }, + { + id: 13, + name: 'Australia', + code2: 'AU', + code3: 'AUS' + }, + { + id: 14, + name: 'Austria', + code2: 'AT', + code3: 'AUT' + }, + { + id: 15, + name: 'Azerbaijan', + code2: 'AZ', + code3: 'AZE' + }, + { + id: 16, + name: 'Bahamas, The', + code2: 'BS', + code3: 'BHS' + }, + { + id: 17, + name: 'Bahrain', + code2: 'BH', + code3: 'BHR' + }, + { + id: 18, + name: 'Bangladesh', + code2: 'BD', + code3: 'BGD' + }, + { + id: 19, + name: 'Barbados', + code2: 'BB', + code3: 'BRB' + }, + { + id: 20, + name: 'Belarus', + code2: 'BY', + code3: 'BLR' + }, + { + id: 21, + name: 'Belgium', + code2: 'BE', + code3: 'BEL' + }, + { + id: 22, + name: 'Belize', + code2: 'BZ', + code3: 'BLZ' + }, + { + id: 23, + name: 'Benin', + code2: 'BJ', + code3: 'BEN' + }, + { + id: 24, + name: 'Bermuda', + code2: 'BM', + code3: 'BMU' + }, + { + id: 25, + name: 'Bhutan', + code2: 'BT', + code3: 'BTN' + }, + { + id: 26, + name: 'Bolivia', + code2: 'BO', + code3: 'BOL' + }, + { + id: 27, + name: 'Bonaire, Sint Eustatius and Saba', + code2: 'BQ', + code3: 'BES' + }, + { + id: 28, + name: 'Bosnia and Herzegovina', + code2: 'BA', + code3: 'BIH' + }, + { + id: 29, + name: 'Botswana', + code2: 'BW', + code3: 'BWA' + }, + { + id: 30, + name: 'Bouvet Island', + code2: 'BV', + code3: 'BVT' + }, + { + id: 31, + name: 'Brazil', + code2: 'BR', + code3: 'BRA' + }, + { + id: 32, + name: 'British Indian Ocean Territory', + code2: 'IO', + code3: 'IOT' + }, + { + id: 33, + name: 'Brunei', + code2: 'BN', + code3: 'BRN' + }, + { + id: 34, + name: 'Bulgaria', + code2: 'BG', + code3: 'BGR' + }, + { + id: 35, + name: 'Burkina Faso', + code2: 'BF', + code3: 'BFA' + }, + { + id: 36, + name: 'Burundi', + code2: 'BI', + code3: 'BDI' + }, + { + id: 37, + name: 'Cabo Verde', + code2: 'CV', + code3: 'CPV' + }, + { + id: 38, + name: 'Cambodia', + code2: 'KH', + code3: 'KHM' + }, + { + id: 39, + name: 'Cameroon', + code2: 'CM', + code3: 'CMR' + }, + { + id: 40, + name: 'Canada', + code2: 'CA', + code3: 'CAN' + }, + { + id: 41, + name: 'Cayman Islands', + code2: 'KY', + code3: 'CYM' + }, + { + id: 42, + name: 'Central African Republic', + code2: 'CF', + code3: 'CAF' + }, + { + id: 43, + name: 'Chad', + code2: 'TD', + code3: 'TCD' + }, + { + id: 44, + name: 'Chile', + code2: 'CL', + code3: 'CHL' + }, + { + id: 45, + name: 'China', + code2: 'CN', + code3: 'CHN' + }, + { + id: 46, + name: 'Christmas Island', + code2: 'CX', + code3: 'CXR' + }, + { + id: 47, + name: 'Cocos (Keeling) Islands', + code2: 'CC', + code3: 'CCK' + }, + { + id: 48, + name: 'Colombia', + code2: 'CO', + code3: 'COL' + }, + { + id: 49, + name: 'Comoros', + code2: 'KM', + code3: 'COM' + }, + { + id: 50, + name: 'Congo', + code2: 'CG', + code3: 'COG' + }, + { + id: 51, + name: 'Congo (DRC)', + code2: 'CD', + code3: 'COD' + }, + { + id: 52, + name: 'Cook Islands', + code2: 'CK', + code3: 'COK' + }, + { + id: 53, + name: 'Costa Rica', + code2: 'CR', + code3: 'CRI' + }, + { + id: 54, + name: 'Croatia', + code2: 'HR', + code3: 'HRV' + }, + { + id: 55, + name: 'Cuba', + code2: 'CU', + code3: 'CUB' + }, + { + id: 56, + name: 'Curaçao', + code2: 'CW', + code3: 'CUW' + }, + { + id: 57, + name: 'Cyprus', + code2: 'CY', + code3: 'CYP' + }, + { + id: 58, + name: 'Czech Republic', + code2: 'CZ', + code3: 'CZE' + }, + { + id: 59, + name: 'Côte d\'Ivoire', + code2: 'CI', + code3: 'CIV' + }, + { + id: 60, + name: 'Democratic Republic of Timor-Leste', + code2: 'TL', + code3: 'TLS' + }, + { + id: 61, + name: 'Denmark', + code2: 'DK', + code3: 'DNK' + }, + { + id: 62, + name: 'Djibouti', + code2: 'DJ', + code3: 'DJI' + }, + { + id: 63, + name: 'Dominica', + code2: 'DM', + code3: 'DMA' + }, + { + id: 64, + name: 'Dominican Republic', + code2: 'DO', + code3: 'DOM' + }, + { + id: 65, + name: 'Ecuador', + code2: 'EC', + code3: 'ECU' + }, + { + id: 66, + name: 'Egypt', + code2: 'EG', + code3: 'EGY' + }, + { + id: 67, + name: 'El Salvador', + code2: 'SV', + code3: 'SLV' + }, + { + id: 68, + name: 'Equatorial Guinea', + code2: 'GQ', + code3: 'GNQ' + }, + { + id: 69, + name: 'Eritrea', + code2: 'ER', + code3: 'ERI' + }, + { + id: 70, + name: 'Estonia', + code2: 'EE', + code3: 'EST' + }, + { + id: 71, + name: 'Ethiopia', + code2: 'ET', + code3: 'ETH' + }, + { + id: 72, + name: 'Falkland Islands (Islas Malvinas)', + code2: 'FK', + code3: 'FLK' + }, + { + id: 73, + name: 'Faroe Islands', + code2: 'FO', + code3: 'FRO' + }, + { + id: 74, + name: 'Fiji Islands', + code2: 'FJ', + code3: 'FJI' + }, + { + id: 75, + name: 'Finland', + code2: 'FI', + code3: 'FIN' + }, + { + id: 76, + name: 'France', + code2: 'FR', + code3: 'FRA' + }, + { + id: 77, + name: 'French Guiana', + code2: 'GF', + code3: 'GUF' + }, + { + id: 78, + name: 'French Polynesia', + code2: 'PF', + code3: 'PYF' + }, + { + id: 79, + name: 'French Southern and Antarctic Lands', + code2: 'TF', + code3: 'ATF' + }, + { + id: 80, + name: 'Gabon', + code2: 'GA', + code3: 'GAB' + }, + { + id: 81, + name: 'Gambia, The', + code2: 'GM', + code3: 'GMB' + }, + { + id: 82, + name: 'Georgia', + code2: 'GE', + code3: 'GEO' + }, + { + id: 83, + name: 'Germany', + code2: 'DE', + code3: 'DEU' + }, + { + id: 84, + name: 'Ghana', + code2: 'GH', + code3: 'GHA' + }, + { + id: 85, + name: 'Gibraltar', + code2: 'GI', + code3: 'GIB' + }, + { + id: 86, + name: 'Greece', + code2: 'GR', + code3: 'GRC' + }, + { + id: 87, + name: 'Greenland', + code2: 'GL', + code3: 'GRL' + }, + { + id: 88, + name: 'Grenada', + code2: 'GD', + code3: 'GRD' + }, + { + id: 89, + name: 'Guadeloupe', + code2: 'GP', + code3: 'GLP' + }, + { + id: 90, + name: 'Guam', + code2: 'GU', + code3: 'GUM' + }, + { + id: 91, + name: 'Guatemala', + code2: 'GT', + code3: 'GTM' + }, + { + id: 92, + name: 'Guernsey', + code2: 'GG', + code3: 'GGY' + }, + { + id: 93, + name: 'Guinea', + code2: 'GN', + code3: 'GIN' + }, + { + id: 94, + name: 'Guinea-Bissau', + code2: 'GW', + code3: 'GNB' + }, + { + id: 95, + name: 'Guyana', + code2: 'GY', + code3: 'GUY' + }, + { + id: 96, + name: 'Haiti', + code2: 'HT', + code3: 'HTI' + }, + { + id: 97, + name: 'Heard Island and McDonald Islands', + code2: 'HM', + code3: 'HMD' + }, + { + id: 98, + name: 'Honduras', + code2: 'HN', + code3: 'HND' + }, + { + id: 99, + name: 'Hong Kong SAR', + code2: 'HK', + code3: 'HKG' + }, + { + id: 100, + name: 'Hungary', + code2: 'HU', + code3: 'HUN' + }, + { + id: 101, + name: 'Iceland', + code2: 'IS', + code3: 'ISL' + }, + { + id: 102, + name: 'India', + code2: 'IN', + code3: 'IND' + }, + { + id: 103, + name: 'Indonesia', + code2: 'ID', + code3: 'IDN' + }, + { + id: 104, + name: 'Iran', + code2: 'IR', + code3: 'IRN' + }, + { + id: 105, + name: 'Iraq', + code2: 'IQ', + code3: 'IRQ' + }, + { + id: 106, + name: 'Ireland', + code2: 'IE', + code3: 'IRL' + }, + { + id: 107, + name: 'Israel', + code2: 'IL', + code3: 'ISR' + }, + { + id: 108, + name: 'Italy', + code2: 'IT', + code3: 'ITA' + }, + { + id: 109, + name: 'Jamaica', + code2: 'JM', + code3: 'JAM' + }, + { + id: 110, + name: 'Jan Mayen', + code2: 'SJ', + code3: 'SJM' + }, + { + id: 111, + name: 'Japan', + code2: 'JP', + code3: 'JPN' + }, + { + id: 112, + name: 'Jersey', + code2: 'JE', + code3: 'JEY' + }, + { + id: 113, + name: 'Jordan', + code2: 'JO', + code3: 'JOR' + }, + { + id: 114, + name: 'Kazakhstan', + code2: 'KZ', + code3: 'KAZ' + }, + { + id: 115, + name: 'Kenya', + code2: 'KE', + code3: 'KEN' + }, + { + id: 116, + name: 'Kiribati', + code2: 'KI', + code3: 'KIR' + }, + { + id: 117, + name: 'Korea', + code2: 'KR', + code3: 'KOR' + }, + { + id: 118, + name: 'Kosovo', + code2: 'XK', + code3: 'XKX' + }, + { + id: 119, + name: 'Kuwait', + code2: 'KW', + code3: 'KWT' + }, + { + id: 120, + name: 'Kyrgyzstan', + code2: 'KG', + code3: 'KGZ' + }, + { + id: 121, + name: 'Laos', + code2: 'LA', + code3: 'LAO' + }, + { + id: 122, + name: 'Latvia', + code2: 'LV', + code3: 'LVA' + }, + { + id: 123, + name: 'Lebanon', + code2: 'LB', + code3: 'LBN' + }, + { + id: 124, + name: 'Lesotho', + code2: 'LS', + code3: 'LSO' + }, + { + id: 125, + name: 'Liberia', + code2: 'LR', + code3: 'LBR' + }, + { + id: 126, + name: 'Libya', + code2: 'LY', + code3: 'LBY' + }, + { + id: 127, + name: 'Liechtenstein', + code2: 'LI', + code3: 'LIE' + }, + { + id: 128, + name: 'Lithuania', + code2: 'LT', + code3: 'LTU' + }, + { + id: 129, + name: 'Luxembourg', + code2: 'LU', + code3: 'LUX' + }, + { + id: 130, + name: 'Macao SAR', + code2: 'MO', + code3: 'MAC' + }, + { + id: 131, + name: 'Macedonia, Former Yugoslav Republic of', + code2: 'MK', + code3: 'MKD' + }, + { + id: 132, + name: 'Madagascar', + code2: 'MG', + code3: 'MDG' + }, + { + id: 133, + name: 'Malawi', + code2: 'MW', + code3: 'MWI' + }, + { + id: 134, + name: 'Malaysia', + code2: 'MY', + code3: 'MYS' + }, + { + id: 135, + name: 'Maldives', + code2: 'MV', + code3: 'MDV' + }, + { + id: 136, + name: 'Mali', + code2: 'ML', + code3: 'MLI' + }, + { + id: 137, + name: 'Malta', + code2: 'MT', + code3: 'MLT' + }, + { + id: 138, + name: 'Man, Isle of', + code2: 'IM', + code3: 'IMN' + }, + { + id: 139, + name: 'Marshall Islands', + code2: 'MH', + code3: 'MHL' + }, + { + id: 140, + name: 'Martinique', + code2: 'MQ', + code3: 'MTQ' + }, + { + id: 141, + name: 'Mauritania', + code2: 'MR', + code3: 'MRT' + }, + { + id: 142, + name: 'Mauritius', + code2: 'MU', + code3: 'MUS' + }, + { + id: 143, + name: 'Mayotte', + code2: 'YT', + code3: 'MYT' + }, + { + id: 144, + name: 'Mexico', + code2: 'MX', + code3: 'MEX' + }, + { + id: 145, + name: 'Micronesia', + code2: 'FM', + code3: 'FSM' + }, + { + id: 146, + name: 'Moldova', + code2: 'MD', + code3: 'MDA' + }, + { + id: 147, + name: 'Monaco', + code2: 'MC', + code3: 'MCO' + }, + { + id: 148, + name: 'Mongolia', + code2: 'MN', + code3: 'MNG' + }, + { + id: 149, + name: 'Montenegro', + code2: 'ME', + code3: 'MNE' + }, + { + id: 150, + name: 'Montserrat', + code2: 'MS', + code3: 'MSR' + }, + { + id: 151, + name: 'Morocco', + code2: 'MA', + code3: 'MAR' + }, + { + id: 152, + name: 'Mozambique', + code2: 'MZ', + code3: 'MOZ' + }, + { + id: 153, + name: 'Myanmar', + code2: 'MM', + code3: 'MMR' + }, + { + id: 154, + name: 'Namibia', + code2: 'NA', + code3: 'NAM' + }, + { + id: 155, + name: 'Nauru', + code2: 'NR', + code3: 'NRU' + }, + { + id: 156, + name: 'Nepal', + code2: 'NP', + code3: 'NPL' + }, + { + id: 157, + name: 'Netherlands', + code2: 'NL', + code3: 'NLD' + }, + { + id: 158, + name: 'New Caledonia', + code2: 'NC', + code3: 'NCL' + }, + { + id: 159, + name: 'New Zealand', + code2: 'NZ', + code3: 'NZL' + }, + { + id: 160, + name: 'Nicaragua', + code2: 'NI', + code3: 'NIC' + }, + { + id: 161, + name: 'Niger', + code2: 'NE', + code3: 'NER' + }, + { + id: 162, + name: 'Nigeria', + code2: 'NG', + code3: 'NGA' + }, + { + id: 163, + name: 'Niue', + code2: 'NU', + code3: 'NIU' + }, + { + id: 164, + name: 'Norfolk Island', + code2: 'NF', + code3: 'NFK' + }, + { + id: 165, + name: 'North Korea', + code2: 'KP', + code3: 'PRK' + }, + { + id: 166, + name: 'Northern Mariana Islands', + code2: 'MP', + code3: 'MNP' + }, + { + id: 167, + name: 'Norway', + code2: 'NO', + code3: 'NOR' + }, + { + id: 168, + name: 'Oman', + code2: 'OM', + code3: 'OMN' + }, + { + id: 169, + name: 'Pakistan', + code2: 'PK', + code3: 'PAK' + }, + { + id: 170, + name: 'Palau', + code2: 'PW', + code3: 'PLW' + }, + { + id: 171, + name: 'Palestinian Authority', + code2: 'PS', + code3: 'PSE' + }, + { + id: 172, + name: 'Panama', + code2: 'PA', + code3: 'PAN' + }, + { + id: 173, + name: 'Papua New Guinea', + code2: 'PG', + code3: 'PNG' + }, + { + id: 174, + name: 'Paraguay', + code2: 'PY', + code3: 'PRY' + }, + { + id: 175, + name: 'Peru', + code2: 'PE', + code3: 'PER' + }, + { + id: 176, + name: 'Philippines', + code2: 'PH', + code3: 'PHL' + }, + { + id: 177, + name: 'Pitcairn Islands', + code2: 'PN', + code3: 'PCN' + }, + { + id: 178, + name: 'Poland', + code2: 'PL', + code3: 'POL' + }, + { + id: 179, + name: 'Portugal', + code2: 'PT', + code3: 'PRT' + }, + { + id: 180, + name: 'Puerto Rico', + code2: 'PR', + code3: 'PRI' + }, + { + id: 181, + name: 'Qatar', + code2: 'QA', + code3: 'QAT' + }, + { + id: 182, + name: 'Reunion', + code2: 'RE', + code3: 'REU' + }, + { + id: 183, + name: 'Romania', + code2: 'RO', + code3: 'ROM' + }, + { + id: 184, + name: 'Russia', + code2: 'RU', + code3: 'RUS' + }, + { + id: 185, + name: 'Rwanda', + code2: 'RW', + code3: 'RWA' + }, + { + id: 186, + name: 'Saint Martin (French part)', + code2: 'MF', + code3: 'MAF' + }, + { + id: 187, + name: 'Saudi Arabia', + code2: 'SA', + code3: 'SAU' + }, + { + id: 188, + name: 'Singapore', + code2: 'SG', + code3: 'SGP' + }, + { + id: 189, + name: 'Slovakia', + code2: 'SK', + code3: 'SVK' + }, + { + id: 190, + name: 'Slovenia', + code2: 'SI', + code3: 'SVN' + }, + { + id: 191, + name: 'Solomon Islands', + code2: 'SB', + code3: 'SLB' + }, + { + id: 192, + name: 'South Africa', + code2: 'ZA', + code3: 'ZAF' + }, + { + id: 193, + name: 'South Georgia and the South Sandwich Islands', + code2: 'GS', + code3: 'SGS' + }, + { + id: 194, + name: 'Spain', + code2: 'ES', + code3: 'ESP' + }, + { + id: 195, + name: 'Turks and Caicos Islands', + code2: 'TC', + code3: 'TCA' + }, + { + id: 196, + name: 'U.S. Minor Outlying Islands', + code2: 'UM', + code3: 'UMI' + }, + { + id: 197, + name: 'United Arab Emirates', + code2: 'AE', + code3: 'ARE' + }, + { + id: 198, + name: 'United States', + code2: 'US', + code3: 'USA' + }, + { + id: 199, + name: 'Virgin Islands, British', + code2: 'VG', + code3: 'VGB' + }, + { + id: 200, + name: 'Virgin Islands, U.S.', + code2: 'VI', + code3: 'VIR' + }, + { + id: 201, + name: 'Yemen', + code2: 'YE', + code3: 'YEM' + }, + { + id: 202, + name: 'Åland Islands', + code2: 'AX', + code3: 'ALA' + }, + { + id: 203, + name: '', + code2: 'EH', + code3: 'ESH' + }, + { + id: 204, + name: 'Bolivarian Republic of Venezuela', + code2: 'VE', + code3: 'VEN' + }, + { + id: 205, + name: 'Saint Barthélemy', + code2: 'BL', + code3: 'BLM' + }, + { + id: 206, + name: 'Saint Helena, Ascension and Tristan da Cunha', + code2: 'SH', + code3: 'SHN' + }, + { + id: 207, + name: 'Saint Kitts and Nevis', + code2: 'KN', + code3: 'KNA' + }, + { + id: 208, + name: 'Saint Lucia', + code2: 'LC', + code3: 'LCA' + }, + { + id: 209, + name: 'Saint Pierre and Miquelon', + code2: 'PM', + code3: 'SPM' + }, + { + id: 210, + name: 'Saint Vincent and the Grenadines', + code2: 'VC', + code3: 'VCT' + }, + { + id: 211, + name: 'Samoa', + code2: 'WS', + code3: 'WSM' + }, + { + id: 212, + name: 'San Marino', + code2: 'SM', + code3: 'SMR' + }, + { + id: 213, + name: 'Senegal', + code2: 'SN', + code3: 'SEN' + }, + { + id: 214, + name: 'Serbia', + code2: 'RS', + code3: 'SRB' + }, + { + id: 215, + name: 'Seychelles', + code2: 'SC', + code3: 'SYC' + }, + { + id: 216, + name: 'Sierra Leone', + code2: 'SL', + code3: 'SLE' + }, + { + id: 217, + name: 'Sint Maarten (Dutch part)', + code2: 'SX', + code3: 'SXM' + }, + { + id: 218, + name: 'Somalia', + code2: 'SO', + code3: 'SOM' + }, + { + id: 219, + name: 'South Sudan', + code2: 'SS', + code3: 'SSD' + }, + { + id: 220, + name: 'Sri Lanka', + code2: 'LK', + code3: 'LKA' + }, + { + id: 221, + name: 'Sudan', + code2: 'SD', + code3: 'SDN' + }, + { + id: 222, + name: 'Suriname', + code2: 'SR', + code3: 'SUR' + }, + { + id: 223, + name: 'Swaziland', + code2: 'SZ', + code3: 'SWZ' + }, + { + id: 224, + name: 'Sweden', + code2: 'SE', + code3: 'SWE' + }, + { + id: 225, + name: 'Switzerland', + code2: 'CH', + code3: 'CHE' + }, + { + id: 226, + name: 'Syria', + code2: 'SY', + code3: 'SYR' + }, + { + id: 227, + name: 'São Tomé and Príncipe', + code2: 'ST', + code3: 'STP' + }, + { + id: 228, + name: 'Taiwan', + code2: 'TW', + code3: 'TWN' + }, + { + id: 229, + name: 'Tajikistan', + code2: 'TJ', + code3: 'TJK' + }, + { + id: 230, + name: 'Tanzania', + code2: 'TZ', + code3: 'TZA' + }, + { + id: 231, + name: 'Thailand', + code2: 'TH', + code3: 'THA' + }, + { + id: 232, + name: 'Togo', + code2: 'TG', + code3: 'TGO' + }, + { + id: 233, + name: 'Tokelau', + code2: 'TK', + code3: 'TKL' + }, + { + id: 234, + name: 'Tonga', + code2: 'TO', + code3: 'TON' + }, + { + id: 235, + name: 'Trinidad and Tobago', + code2: 'TT', + code3: 'TTO' + }, + { + id: 236, + name: 'Tunisia', + code2: 'TN', + code3: 'TUN' + }, + { + id: 237, + name: 'Turkey', + code2: 'TR', + code3: 'TUR' + }, + { + id: 238, + name: 'Turkmenistan', + code2: 'TM', + code3: 'TKM' + }, + { + id: 239, + name: 'Tuvalu', + code2: 'TV', + code3: 'TUV' + }, + { + id: 240, + name: 'Uganda', + code2: 'UG', + code3: 'UGA' + }, + { + id: 241, + name: 'Ukraine', + code2: 'UA', + code3: 'UKR' + }, + { + id: 242, + name: 'United Kingdom', + code2: 'GB', + code3: 'GBR' + }, + { + id: 243, + name: 'Uruguay', + code2: 'UY', + code3: 'URY' + }, + { + id: 244, + name: 'Uzbekistan', + code2: 'UZ', + code3: 'UZB' + }, + { + id: 245, + name: 'Vanuatu', + code2: 'VU', + code3: 'VUT' + }, + { + id: 246, + name: 'Vatican City', + code2: 'VA', + code3: 'VAT' + }, + { + id: 247, + name: 'Vietnam', + code2: 'VN', + code3: 'VNM' + }, + { + id: 248, + name: 'Wallis and Futuna', + code2: 'WF', + code3: 'WLF' + }, + { + id: 249, + name: 'Zambia', + code2: 'ZM', + code3: 'ZMB' + }, + { + id: 250, + name: 'Zimbabwe', + code2: 'ZW', + code3: 'ZWE' + } +] diff --git a/packages/albus-sdk/src/utils/index.ts b/packages/albus-sdk/src/utils/index.ts index c51fbaf1..babd9e70 100644 --- a/packages/albus-sdk/src/utils/index.ts +++ b/packages/albus-sdk/src/utils/index.ts @@ -29,3 +29,4 @@ export * from './circuit' export * from './wallet' export * from './web3' +export * from './policy-formatter' diff --git a/packages/albus-sdk/src/utils/policy-formatter.ts b/packages/albus-sdk/src/utils/policy-formatter.ts new file mode 100644 index 00000000..4241e350 --- /dev/null +++ b/packages/albus-sdk/src/utils/policy-formatter.ts @@ -0,0 +1,164 @@ +import type { PublicKey } from '@solana/web3.js' +import { COUNTRIES_LIST } from '../countries' +import { PolicyRule } from '../generated' + +export enum Circuit { + Age = 'age', + Attendance = 'attendance', + Liveness = 'liveness', + Country = 'country', +} + +const EVENTS = { + cacf: 'Crypto assets conference, Frankfurt', + sb2023a: 'Solana breakpoint 2023, Amsterdam', + ws2023l: 'Web summit 2023, Lisbon', + cbbd: 'Chains beyond borders, Dubai', +} + +const KEYS = { + selectionMode: 'mode', + countryLookup: 'country(ies)', + expectedEvent: 'event', + expectedDateFrom: 'date from', + expectedDateTo: 'date to', + expectedType: 'verifying issuer', +} + +const LABELS = { + selectionMode_true: 'includes', + selectionMode_false: 'excludes', + ...Object.keys(EVENTS).reduce((acc, cur) => ({ ...acc, [`expectedEvent_${cur}`]: EVENTS[cur] }), {}), +} + +function formateDate(time: number, options?: { [key: string]: string }) { + if (Number.isNaN(time)) { + return '0' + } + const formatter = new Intl.DateTimeFormat('uk-Uk', options ?? { + day: 'numeric', + month: 'numeric', + year: 'numeric', + }) + return formatter.format(time) +} + +function secondsToMilliseconds(sec: number): number { + return sec * 1000 +} + +function formatCamelCase(str: string) { + return str.split(/(?=[A-Z])/).join(' ').toLowerCase() +} + +function hasKey(rules: PolicyRule[], key: string) { + return !!rules.find(r => r.key === key) +} + +function getCircuitByRules(rules: PolicyRule[]): Circuit | null { + if ( + hasKey(rules, 'minAge') + && ( + rules.length === 1 + || (rules.length === 2 && hasKey(rules, 'maxAge')) + ) + ) { + return Circuit.Age + } else if ( + rules.length === 3 + && hasKey(rules, 'expectedEvent') + && hasKey(rules, 'expectedDateFrom') + && hasKey(rules, 'expectedDateTo') + ) { + return Circuit.Attendance + } else if ( + rules.length === 3 + && hasKey(rules, 'selectionMode') + && hasKey(rules, 'countryLookup.0') + && hasKey(rules, 'countryLookup.1') + ) { + return Circuit.Liveness + } else if ( + rules.length === 1 + && hasKey(rules, 'expectedType') + ) { + return Circuit.Country + } + return null +} + +function normalizeRule({ key, label, value }: { key: string; label: string; value: number[] }): PolicyRuleNormalized { + const keyFormatted = KEYS[key] ?? formatCamelCase(key) + let valueFormatted = '' + if (key === 'countryLookup') { + valueFormatted = value + .filter(v => v > 0) + .reduce((acc, cur, idx) => `${acc}${idx > 0 ? ', ' : ''}${COUNTRIES_LIST[cur - 1]?.name}`, '') + } else { + valueFormatted = LABELS[`${key}_${label}`] ?? label + } + return { + key: keyFormatted, + value: valueFormatted, + } +} + +function groupRules(props: PolicyRule[]): PolicyRule[] { + const list: Record = {} + props.forEach((r, idx) => { + const name = r.key.split('.')[0] ?? '' + if (!list[name]) { + list[name] = [] + } + list[name]?.push(idx) + }) + const rules: PolicyRule[] = [] + for (const key in list) { + rules.push({ + key, + label: props[list[key]?.[0] ?? '']?.label, + value: list[key]?.reduce((acc: number[], cur: number) => [...acc, ...(props[cur]?.value ?? [])], []) ?? [], + }) + } + return rules +} + +export function normalizePolicyRules(props: PolicyRule[]): PolicyRuleNormalized[] { + const groups = groupRules(props) + return groups.map(g => normalizeRule(g)) +} + +export function formatPolicyRules(data: { circuit: PublicKey; rules: PolicyRule[] }): string { + const rules = normalizePolicyRules(data.rules) + switch (getCircuitByRules(data.rules)) { + case Circuit.Age: { + const to = rules[1]?.value !== '100' ? `to ${rules[1]?.value}` : '' + return `Age: from ${data.rules[0]?.label} ${to}` + } + case Circuit.Attendance: { + const expectedDateFrom = Number(rules[1]?.value) + const expectedDateTo = Number(rules[2]?.value) + + let to = '∞' + if (!Number.isNaN(expectedDateTo) && expectedDateTo !== 0) { + to = String(formateDate(secondsToMilliseconds(expectedDateTo))) + } + const from = formateDate(secondsToMilliseconds(expectedDateFrom)) + const event = rules[0]?.value + return `Event: ${event}, Date: ${from} - ${to}` + } + case Circuit.Liveness: { + return `Verifying issuer: ${rules[0]?.value}` + } + case Circuit.Country: { + return `Mode: ${rules[0]?.value}. Countries: ${rules[1]?.value}` + } + default: + return '' + } +} + +export interface PolicyRuleNormalized { + key: string + value: string +}