namespace formgen.helpers.zerez { /** */ type type_credentials = { base_url : string; token_url : string; scope : string; client_id : string; client_secret : string; }; /** */ var _credentials : type_credentials; /** */ var _token : (null | string) = null; /** * @todo set to false/remove */ var _fake : boolean = false; async function get_token( ) : Promise { if (_fake) { _token = "fake"; return _token; } else { /** * this does not work due to CORS restrictions on the zerez server; to solve this, a proxy/backend is be required */ if (_token === null) { _token = await ( fetch( _credentials.token_url, { "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "Guzzle/4.0 curl/7.21.4 PHP/5.5.7", }, "body": ( (new URLSearchParams( { "grant_type": "client_credentials", "client_id": _credentials.client_id, "client_secret": _credentials.client_secret, "scope": _credentials.scope, } )) .toString() ), } ) .then( x => x.json() ) .then( x => x["access_token"] ) .catch( (error) => Promise.resolve(null) ) ); if (_token === null) { throw (new Error("could not fetch token")); } else { return _token; } } else { return _token; } } } /** */ export async function get_unit( id : string ) : Promise { const bearer : string = await get_token(); if (_fake) { return { "deep_link": "https:\/\/www.zerez.net\/units\/6314260b-364a-4d53-368d-08dd4b5a9353", "unit_zerez_code": "ZE-EYVQ-5OEX-0001", "model_number": "ASN-12TL-G2", "model_name": "ASN-12TL-G2", "replaced_by_zerez_code": "", "maximum_active_power_kw": 13.2, "maximum_apparent_power_kva": 13.3, "rated_active_power_kw": 12, "rated_apparent_power_kva": 12, "maximum_active_power_at_0_9_pf_kw": null, "rated_voltage_v": 400, "rated_current_a": 17.3, "peak_short_circuit_current_a": 50, "initial_short_circuit_alternating_current_a": 19.1, "worst_case_operation_scenario_value": 0.74, "net_feed_in_details": "Three-Phase", "flicker_system_coefficient_at_30_cu": 2.3, "flicker_system_coefficient_at_50_cu": 2.3, "flicker_system_coefficient_at_70_cu": 2.3, "flicker_system_coefficient_at_85_cu": 2.3, "max_switch_operations_operation1_n10": null, "max_number_of_operations_operation1_n120": null, "voltage_variation_factor_at_operation1_30_kwv": null, "voltage_variation_factor_at_operation1_50_kwv": null, "voltage_variation_factor_at_operation1_70_kwv": null, "voltage_variation_factor_at_operation1_85_kwv": null, "flicker_step_factor_at_operation1_30_kfv": null, "flicker_step_factor_at_operation1_50_kfv": null, "flicker_step_factor_at_operation1_70_kfv": null, "flicker_step_factor_at_operation1_85_kfv": null, "max_switch_operations_operation2_n10": null, "max_number_of_operations_operation2_n120": null, "voltage_variation_factor_at_operation2_30_kwv": null, "voltage_variation_factor_at_operation2_50_kwv": null, "voltage_variation_factor_at_operation2_70_kwv": null, "voltage_variation_factor_at_operation2_85_kwv": null, "flicker_step_factor_at_operation2_30_kfv": null, "flicker_step_factor_at_operation2_50_kfv": null, "flicker_step_factor_at_operation2_70_kfv": null, "flicker_step_factor_at_operation2_85_kfv": null, "max_no_of_switching_operations_operation3_n10": null, "max_no_of_switching_operations_operation3_n120": null, "voltage_variation_factor_operation3_30_kuf": null, "voltage_variation_factor_operation3_50_kuf": null, "voltage_variation_factor_operation3_70_kuf": null, "voltage_variation_factor_operation3_85_kuf": null, "flicker_step_factor_operation3_30_kff": null, "flicker_step_factor_operation3_50_kff": null, "flicker_step_factor_operation3_70_kff": null, "flicker_step_factor_operation3_85_kff": null, "fast_voltage_change_turn_on_without_specifications": 0.07, "fast_voltage_change_worst_case_during_generator_stage_switching": 0, "fast_voltage_change_turn_on_at_rated_conditions": 0.07, "fast_voltage_change_turn_off_at_rated_power": 0.74, "min_active_power_range_kW": null, "max_active_power_range_kW": null, "min_apparent_power_range_kW": null, "max_apparent_power_range_kW": null, "has_switching_operation_1": null, "has_switching_operation_2": null, "has_switching_operation_3": null, "matrix_type": null, "effective_impedance_reference_point": null, "temporary_minimum_performance": null, "date_of_latest_change": "2025-02-26T13:16:37.2828973", "certificate": { "deep_link": "https:\/\/www.zerez.net\/certificates\/11f20238-f3ee-475f-a52e-0005575c8f06", "certificate_number": "4479823053419", "zerez_id": "ZE-EYVQ-5OEX", "certificate_type": "", "replaced_by": "", "certificate_holder": "Ningbo AUX Solar Technology Co., Ltd.", "certificate_authority": "T\u00dcV NORD CERT GmbH", "certificate_norms": [ { "name": "VDE-AR-N 4105" } ], "certificate_validity_status": "Valid \/ Ongoing", "certificate_issue_date": "2024-11-01T03:17:16.873", "validity_start_date": null, "restrictions": "restricted", "software_environment_version_number": "", "norms": [ "VDE-AR-N 4105:2018-11" ], "validity_end_date": null, "validation_status": "Ongoing Feedback Process", "category": "Inverter", "primary_energy_source": "Photovoltaic", "certificate_files": [ { "certificate_file_name": "RDPVP0705524B03_E4E5.pdf", "certificate_file_type": "Cover Sheet", "certificate_file_description": null, "certificate_file_storage_location": "\/api\/PublicDownload\/F9565FEDFFF684AD065562A198EF3077.A177478D7D94FCA2FBB486A4B8430B91C91C9B1858261B57B51513DB79BE22D8E74C1917BE5DAD731C45CBC7C9567C62469E3FDEBC000BEACF372411668ADC74EC94218BA4F1858E2C161B7D7DE8893CB52072ABCD63A8012E25C4945DC16475A3FB5498052816FFAEA8A5CBC554A586F5715F4C61DCB455F4E13F9E96763A2B1E8B86414AF98F987B0FED8E4F3B80CA78147CBF02E30BEA7D976776A0DD153399D42E078E7BE0413511EE44F5A5E5E08D7C154B5CC9FEEF8C50F63BDD60453CF7C49AF438621DFFB80BD573BFD8DE4B0FDD1F21E003F595AC8790C0EAEA2F925BF85466CE17142258E42A7C716AC7C9AD24C1A694A114C83BB4AC861DB8C7967BDF5172B71154669B6C4A83ACEFF75BBECB52BA36B885B6DAC3B215E3009E7BD3A5D26481FA24F392B58B0E5FDB01C0632E686964B2BF0556667B18BFB07DF78797FCFC6FFCB19AD785FBB038CA3A500E89E57BDEDE8BFA64F58AE921D89DF80911006448B9A93583C670CCCE0F81C6A18D977EDF62CC640016C7FFE9DA8719DA370F599A9FA51298DBE70FB6A18EF7BD0155625B1A361EB4080F1EBC2DC545987023A9C7EBB83CDC569D4FB3328CC21741D9648A321468DC101037C1D3426DF753E31C15DB29FEC50D3288A4148C1CFC8A217714A8D4B998D172E588D6A94345CF986EFCA32D85C159016CEA79F03DE1F2E90424567B949CA3BFEB78830E4591CBC5A521FA636483866106C19187AF1812D3014B253707E1E484749E7C4F4EEC70E1530C35076A708C12E2A775A47AD73544FD9B68A7DFC8BE33B02EF4987C", "expiration": "2026-09-29T20:25:43.0561735Z" }, { "certificate_file_name": "RDPVP0705524B03_E7.pdf", "certificate_file_type": "Perturbations Test Report", "certificate_file_description": null, "certificate_file_storage_location": "\/api\/PublicDownload\/74EB90CE7416C2085FEE1A996C19F753.5514D632B01CC208B2D1E24EA97950F06F903B12E646F387362D1D32B6753390CDCE5B369973965A275D9EDB5DDEA57E743743E7E1F45C2B23A9D085AECBF2ED627939D75E2747F75665705DEF68A5A325452271B91FB922AD6B96B91C45AE80A142E84ED08658E1FB1D456A5DBDDE3073D3184A80579973D62DE7B035E7B3AFA462449E3DF3FA528078401EC92E7F9C0762D9AA138D0EDFB39D944C15ABF949A2C1ED8C60E37719A63805F3BF16720A7FC304819A5223D58A4DF56FB0A8EA1032D20041C603723DDD09177134E6F413D74FBD519490F2B7DD1B7D72C70E9E652EF1450C314F25343A325886EC55087ED33B98AF335DCACD7E0E8BC40E62CCD9AE9BA5375A772C3A0C2E8B2E21C98297AD66EF46EF28934B4EF16BEBE2D91D01C3CDBBBCB33F65C70253C732550BEAC84F55ACF5BC4BC6B006C87D96319E89DB6FDE4F5774E3B711BB10A23FF66B8BBAAEC09E541AD8A8324CECE399F53283A82079F73CF13E75CD3CB0AE6FFF90C49912C26F8AC3CD3E909E1DFA39B80B009F8187EC723830F55F4AF554A4C3416DADD3E71CA8F132EBFC9F335015BFD8DF78C2357AC4D784B8A26983EF202819921C28E6D7C16D46F8D047E771927691F25EAF8AA9735993B2D6C87E792F5156014F448295CF6C725F7ADF7ACFA17D9DDCC19A4C772BFC3816817E37A8F180F98FAF13BB84831EB9419A47EF5A21B56F92C0747341BCADD2AA399AB23FAAA945C4AF2F84A4EABED27364487E940F6DF44E2E569826DAE6BFE2D3892525308615886E561AACD9A5D44F816443A145EA9B6DF3", "expiration": "2026-09-29T20:25:43.0562281Z" } ], "date_of_latest_change": "2025-02-26T13:16:36.7226181" } }; } else { return ( fetch( formgen.helpers.string.coin( "{{base_url}}/api/v1/units/{{id}}", { "base_url": _credentials.base_url, "id": id, } ), { "headers": { "Authorization": ("Bearer " + bearer), "Accept": "application/json", // "Content-Type": "application/json", } } ) .then( x => x.json() ) ); } } /** */ export async function initialize( credentials : type_credentials, { "fake": fake = false, } : { fake ?: boolean; } = { } ) : Promise { _credentials = credentials; _fake = fake; await get_token(); } }