1import{a as te}from"./chunk-JB3UKYJF.js";import"./chunk-64MUE7TD.js";import"./chunk-IPRTGYVJ.js";import"./chunk-RYWZ6RDH.js";import{d as ee}from"./chunk-UTRFG6UA.js";import{a as Z,d as Q}from"./chunk-ORHW456O.js";import{E as D,Fd as $,Gd as G,Hd as S,Id as z,Ma as K,Na as V,Oc as Y,Pc as H,Pd as q,Qc as X,Rc as j,Tc as W,Uc as J,Vc as I,Xa as B,xa as O}from"./chunk-IJDBQKGN.js";import"./chunk-B5YGGBPK.js";import"./chunk-4R7TFJ2A.js";import{Bc as N,Eb as a,Ja as g,Ka as f,Kb as v,Mc as r,Nc as C,Oc as k,Rb as F,Xb as x,dc as m,kc as c,pc as s,qc as o,rc as P,vc as A,xc as _,y as R,yc as d}from"./chunk-WPW6PZDG.js";import{g as L}from"./chunk-GAL4ENT6.js";var ie=(()=>{class n{constructor(e,t){this.dialogRef=e,this.message=t}onNoClick(){this.dialogRef.close()}static{this.\u0275fac=function(t){return new(t||n)(v(Y),v(H))}}static{this.\u0275cmp=F({type:n,selectors:[["app-confirmation-dialog"]],decls:7,vars:2,consts:[["mat-dialog-content",""],["mat-dialog-actions",""],["mat-button","",3,"click"],["mat-button","","cdkFocusInitial","",3,"mat-dialog-close"]],template:function(t,i){t&1&&(s(0,"div",0),r(1),o(),s(2,"div",1)(3,"button",2),_("click",function(){return i.onNoClick()}),r(4,"No"),o(),s(5,"button",3),r(6,"Yes"),o()()),t&2&&(a(),k(" ",i.message,` 2`),a(4),m("mat-dialog-close",!0))},dependencies:[I,j,J,W,Q,Z],encapsulation:2})}}return n})();function ae(n,p){n&1&&(s(0,"div")(1,"p"),r(2,"No API key. You must own a Personal Weather Station in order to generate an API key."),o(),s(3,"p")(4,"a",4),r(5,"Learn More"),o()()())}function se(n,p){n&1&&(s(0,"small",10),r(1,"You must agree to the Terms of Service."),o())}function re(n,p){if(n&1&&(s(0,"p"),r(1),o()),n&2){let e=d(3);a(),C(e.generateFailedText)}}function le(n,p){if(n&1){let e=A();s(0,"div"),P(1,"input",5),s(2,"div",6)(3,"input",7),_("change",function(i){g(e);let l=d(2);return f(l.updateTosState(i))}),o(),s(4,"label",8),r(5," I agree to the "),s(6,"a",9),r(7,"Terms of Service"),o(),x(8,se,2,0,"small",10),o()(),s(9,"button",11),_("click",function(){g(e);let i=d(2);return f(i.generateApiKey())}),r(10),o(),x(11,re,2,1,"p"),o()}if(n&2){let e=d(2);a(),N("value",e.apiKey),m("type",e.showApiKey?"text":"password"),a(2),m("checked",e.tosChecked),a(5),c(e.showTosErrorText?8:-1),a(),m("disabled",e.modifyKeyPending||!e.tosChecked),a(),C(e.generateButtonText),a(),c(e.generateFailed?11:-1)}}function de(n,p){n&1&&(s(0,"small",10),r(1,"You must agree to the Terms of Service."),o())}function ce(n,p){if(n&1&&(s(0,"p"),r(1),o()),n&2){let e=d(4);a(),C(e.generateFailedText)}}function pe(n,p){if(n&1){let e=A();s(0,"div")(1,"button",11),_("click",function(){g(e);let i=d(3);return f(i.openConfirmationDialog("generate","Are you sure you want to generate a new API key? This cannot be undone."))}),r(2),o(),x(3,ce,2,1,"p"),o()}if(n&2){let e=d(3);a(),m("disabled",e.modifyKeyPending||!e.tosChecked),a(),C(e.generateButtonText),a(),c(e.generateFailed?3:-1)}}function he(n,p){if(n&1&&(s(0,"p"),r(1),o()),n&2){let e=d(4);a(),C(e.regenerateFailedText)}}function ue(n,p){if(n&1){let e=A();s(0,"div")(1,"button",11),_("click",function(){g(e);let i=d(3);return f(i.openConfirmationDialog("regenerate","Are you sure you want to regenerate your API key? This cannot be undone."))}),r(2),o(),x(3,he,2,1,"p"),o()}if(n&2){let e=d(3);a(),m("disabled",e.modifyKeyPending||!e.tosChecked),a(),C(e.regenerateButtonText),a(),c(e.regenerateFailed?3:-1)}}function me(n,p){if(n&1&&(s(0,"p"),r(1),o()),n&2){let e=d(3);a(),C(e.deleteFailedText)}}function _e(n,p){if(n&1&&(s(0,"p"),r(1),o()),n&2){let e=d(4);a(),C(e.keyUsageFailedText)}}function ye(n,p){if(n&1){let e=A();s(0,"div")(1,"button",11),_("click",function(){g(e);let i=d(3);return f(i.getKeyUsage())}),r(2,"Show Usage"),o(),x(3,_e,2,1,"p"),o()}if(n&2){let e=d(3);a(),m("disabled",e.modifyKeyPending),a(2),c(e.keyUsageFailed?3:-1)}}function ge(n,p){if(n&1){let e=A();s(0,"div")(1,"button",11),_("click",function(){g(e);let i=d(3);return f(i.previousDate())}),r(2,"<"),o(),s(3,"strong"),r(4),o(),s(5,"button",11),_("click",function(){g(e);let i=d(3);return f(i.nextDate())}),r(6,">"),o(),P(7,"lib-wu-chart",20),o()}if(n&2){let e=d(3);a(),m("disabled",e.modifyKeyPending),a(3),k("",e.dateText," (UTC Time)"),a(),m("disabled",e.modifyKeyPending||e.nextDateInFuture),a(2),m("data",e.usageGraph)}}function fe(n,p){if(n&1){let e=A();s(0,"div")(1,"div",1)(2,"div",12),P(3,"input",5),s(4,"p"),r(5),o(),s(6,"div",13)(7,"div",14)(8,"button",15),_("click",function(){g(e);let i=d(2);return f(i.copyApiKeyToClipboard())}),r(9,"Copy to Clipboard"),o()(),s(10,"div",14)(11,"button",16),_("click",function(){g(e);let i=d(2);return f(i.toggleViewApiKey())}),r(12),o()()(),s(13,"div",6)(14,"input",7),_("change",function(i){g(e);let l=d(2);return f(l.updateTosState(i))}),o(),s(15,"label",8),r(16," I agree to the "),s(17,"a",9),r(18,"Terms of Service"),o(),x(19,de,2,0,"small",10),o()(),x(20,pe,4,3,"div")(21,ue,4,3,"div"),s(22,"button",11),_("click",function(){g(e);let i=d(2);return f(i.openConfirmationDialog("delete","Are you sure you want to delete your API key? This cannot be undone."))}),r(23),o(),x(24,me,2,1,"p"),o(),s(25,"div",12)(26,"div",17)(27,"h4"),r(28,"Ready to use your key?"),o(),s(29,"p")(30,"a",18),r(31,"View API Documentation"),o()()()()(),s(32,"div",19)(33,"h3"),r(34,"API Key Usage"),o(),x(35,ye,4,2,"div")(36,ge,8,4,"div"),o()()}if(n&2){let e=d(2);a(3),N("value",e.apiKey),m("type",e.showApiKey?"text":"password"),a(2),k("Expires: ",e.expirationText,""),a(7),C(e.showApiKeyButtonText),a(2),m("checked",e.tosChecked),a(5),c(e.showTosErrorText?19:-1),a(),c(e.expiredApiKey?20:-1),a(),c(e.expiredApiKey?-1:21),a(),m("disabled",e.modifyKeyPending),a(),C(e.deleteButtonText),a(),c(e.deleteFailed?24:-1),a(11),c(e.keyUsageDataObtained?-1:35),a(),c(e.keyUsageDataObtained?36:-1)}}function xe(n,p){if(n&1&&(s(0,"div"),x(1,ae,6,0,"div")(2,le,12,7,"div")(3,fe,37,13,"div"),o()),n&2){let e=d();a(),c(!e.hasApiKey&&!e.ownsPws?1:-1),a(),c(!e.hasApiKey&&e.ownsPws?2:-1),a(),c(e.hasApiKey?3:-1)}}function Ce(n,p){n&1&&(s(0,"div")(1,"p"),r(2,"Could not load profile. Try relogging to reload the profile."),o()())}function Te(n,p){n&1&&(s(0,"div")(1,"p"),r(2,"Loading..."),o()())}var Ye=(()=>{class n{constructor(e,t,i,l){this.ups=e,this.upsDal=t,this.memberKeyService=i,this.dialog=l,this.DEFAULT_GENERATE_TEXT="Generate New Key",this.DEFAULT_REGENERATE_TEXT="Regenerate Key",this.DEFAULT_DELETE_TEXT="Delete Key",this.SHOW_API_KEY_TEXT="Show Key",this.HIDE_API_KEY_TEXT="Hide Key",this.MONTH_NAME=["January","February","March","April","May","June","July","August","September","October","November","December"],this.MS_IN_MINUTE=60*1e3,this.MS_IN_HOUR=60*this.MS_IN_MINUTE,this.MS_IN_DAY=24*this.MS_IN_HOUR,this.profileLoaded=!1,this.profileLoadSuccess=!1,this.ownsPws=!1,this.hasApiKey=!1,this.expiredApiKey=!1,this.apiKey="",this.showApiKey=!1,this.showApiKeyButtonText=this.SHOW_API_KEY_TEXT,this.keyUsageDataObtained=!1,this.keyUsageFailed=!1,this.keyUsageFailedText="",this.currentGraphType=K.DAY,this.currentGraphDate=new Date,this.nextDateInFuture=!1,this.tosChecked=!1,this.showTosErrorText=!1,this.modifyKeyPending=!1,this.generateButtonText=this.DEFAULT_GENERATE_TEXT,this.generateFailed=!1,this.generateFailedText="",this.regenerateButtonText=this.DEFAULT_REGENERATE_TEXT,this.regenerateFailed=!1,this.regenerateFailedText="",this.deleteButtonText=this.DEFAULT_DELETE_TEXT,this.deleteFailed=!1,this.deleteFailedText=""}ngOnInit(){this.ups.isUserLoggedIn().subscribe(e=>L(this,null,function*(){e&&(yield this.getApiKey()),this.profileLoaded=!0}))}getApiKey(){this.upsDal.getUserAssets().pipe(R(1)).subscribe({next:e=>L(this,null,function*(){let t=yield e;if(t.status>=400){this.profileLoadSuccess=!1;return}this.setApiKeyDisplay(t.data?.wu?.apiKey),this.ownsPws=(t.data?.wu?.pws??[]).length>0,this.profileLoadSuccess=!0}),error:e=>this.profileLoadSuccess=!1})}setApiKeyDisplay(e){if(this.setStatusGetKeyUsageHide(),this.tosChecked=!1,this.showTosErrorText=!1,!e||e.length==0){this.apiKey="",this.hasApiKey=!1;return}this.expirationText="retrieving...",this.memberKeyService.getKeyData(e).then(t=>{if(!t){this.expiredApiKey=!0,this.expirationText="Key has expired";return}this.expiredApiKey=!1;let i=D(t,"expires","");if(i&&i.length>0){let l=new Date(i);this.expirationText=l.toUTCString();return}this.expirationText="Unknown"},t=>{this.expirationText="Unknown. "+t}),this.apiKey=e,this.hasApiKey=!0}toggleViewApiKey(){this.showApiKey=!this.showApiKey,this.showApiKeyButtonText=this.showApiKey?this.HIDE_API_KEY_TEXT:this.SHOW_API_KEY_TEXT}copyApiKeyToClipboard(){let e=document.createElement("textarea");e.value=this.apiKey,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}updateTosState(e){this.tosChecked=e.target.checked}openConfirmationDialog(e,t){if(e!=="generate"&&e!=="regenerate"&&e!=="delete")return;this.dialog.open(ie,{width:"350px",data:t}).afterClosed().subscribe(l=>{if(l){let T=`${e}ApiKey`;this[T]()}})}generateApiKey(){if(!this.tosChecked){this.showTosErrorText=!0;return}this.showTosErrorText=!1,!this.modifyKeyPending&&(this.setStatusGenKeyPending(),this.memberKeyService.generateApiKey().then(e=>{e&&e.length>0?(this.setApiKeyDisplay(e),this.setStatusGenKeySuccess()):this.setStatusGenKeyFailure("No key was generated. Please try again.")},e=>
2{this.setStatusGenKeyFailure("Key could not be generated. "+e)}))}setStatusGenKeyPending(){this.generateButtonText="Generating...",this.modifyKeyPending=!0,this.generateFailed=!1}setStatusGenKeySuccess(){this.generateButtonText=this.DEFAULT_GENERATE_TEXT,this.modifyKeyPending=!1,this.generateFailed=!1}setStatusGenKeyFailure(e){this.generateButtonText=this.DEFAULT_GENERATE_TEXT,this.modifyKeyPending=!1,this.generateFailedText=e,this.generateFailed=!0}regenerateApiKey(){if(!this.tosChecked){this.showTosErrorText=!0;return}this.showTosErrorText=!1,!this.modifyKeyPending&&(this.setStatusRegenKeyPending(),this.memberKeyService.regenerateApiKey(this.apiKey).then(e=>{e&&e.length>0?(this.setApiKeyDisplay(e),this.setStatusRegenKeySuccess()):this.setStatusRegenKeyFailure("No new key was generated. Please try again.")},e=>{this.setStatusRegenKeyFailure("New key could not be generated. "+e)}))}setStatusRegenKeyPending(){this.regenerateButtonText="Regenerating...",this.modifyKeyPending=!0,this.regenerateFailed=!1}setStatusRegenKeySuccess(){this.regenerateButtonText=this.DEFAULT_REGENERATE_TEXT,this.modifyKeyPending=!1,this.regenerateFailed=!1}setStatusRegenKeyFailure(e){this.regenerateButtonText=this.DEFAULT_REGENERATE_TEXT,this.modifyKeyPending=!1,this.regenerateFailedText=e,this.regenerateFailed=!0}deleteApiKey(){this.modifyKeyPending||(this.setStatusDeleteKeyPending(),this.memberKeyService.deleteApiKey(this.apiKey).then(()=>{this.setApiKeyDisplay(""),this.setStatusDeleteKeySuccess()},e=>{this.setStatusDeleteKeyFailure("Key could not be deleted. "+e)}))}setStatusDeleteKeyPending(){this.deleteButtonText="Deleting...",this.modifyKeyPending=!0,this.deleteFailed=!1}setStatusDeleteKeySuccess(){this.deleteButtonText=this.DEFAULT_DELETE_TEXT,this.modifyKeyPending=!1,this.deleteFailed=!1}setStatusDeleteKeyFailure(e){this.deleteButtonText=this.DEFAULT_DELETE_TEXT,this.modifyKeyPending=!1,this.deleteFailedText=e,this.deleteFailed=!0}getKeyUsage(){this.modifyKeyPending||(this.setStatusGetKeyUsagePending(),this.currentGraphDate=new Date,this.currentGraphType=K.DAY,this.setUsageGraph(this.apiKey,this.currentGraphType,this.currentGraphDate))}setStatusGetKeyUsagePending(){this.modifyKeyPending=!0}setStatusGetKeyUsageSuccess(){this.keyUsageDataObtained=!0,this.modifyKeyPending=!1;let e=this.changeUsageDate(this.currentGraphDate,this.currentGraphType,1),t=new Date;this.nextDateInFuture=e.getTime()>t.getTime()}setStatusGetKeyUsageFailure(e){this.keyUsageFailedText=e,this.keyUsageFailed=!0,this.keyUsageDataObtained=!1,this.modifyKeyPending=!1}setStatusGetKeyUsageHide(){this.keyUsageFailedText="",this.keyUsageFailed=!1,this.keyUsageDataObtained=!1}setUsageGraph(e,t,i){let l=this.MONTH_NAME[i.getUTCMonth()],T=i.getUTCDate(),E=i.getUTCFullYear();var h=G.MONTHLY;switch(t){case K.DAY:{this.dateText=l+" "+E,h=G.MONTHLY;break}case K.HOUR:{this.dateText=l+" "+T+", "+E,h=G.DAILY;break}default:throw new Error("Unsupported graph type "+t)}this.memberKeyService.getKeyUsageData(e,t,i).then(y=>{let u;if(y&&y.length>0&&(u=this.parseUsageJson(y),!u||u.length==0)){this.setStatusGetKeyUsageFailure("Usage data could not be displayed.");return}let w=this.fillMissingData(t,i,u);w.sort((U,M)=>U.epochMs-M.epochMs);let b=i.getTimezoneOffset()*this.MS_IN_MINUTE;this.usageGraph={mode:h,timeSeries:{series:$.TIME,timeZone:"UTC",data:w.map(U=>U.epochMs+b)},charts:[this.createUsageLineCharts(w,b)]},this.setStatusGetKeyUsageSuccess()},y=>{this.setStatusGetKeyUsageFailure("Usage data could not be retrieved. "+y)})}parseUsageJson(e){return e.map(t=>{let i=D(t,"dateTime","");return{epochMs:new Date(i).getTime(),successes:D(t,"successes",0),failures:D(t,"failures",0),errors:D(t,"errors",0)}})}fillMissingData(e,t,i){var l=new Date(t.getTime()),T=0,E=0,h=0;switch(e){case K.DAY:{l.setUTCDate(1),l.setUTCHours(0,0,0,0),T=l.getTime(),E=this.MS_IN_DAY,h=this.getDaysInUTCMonth(t);break}case K.HOUR:{l.setUTCHours(0,0,0,0),T=l.getTime(),E=this.MS_IN_HOUR,h=24;break}default:throw new Error("Unsupported graph type "+e)}var y=new Array(h);if(i&&i.length!=0)for(var u=0;u<i.length;u++){let U=Math.round((i[u].epochMs-T)/E);y[U]=i[u]}let w=new Date().getTime();for(var b=y.length,u=0;u<y.length;u++){let M=T+u*E;if(M<=w)y[u]==null&&(y[u]={epochMs:M,successes:0,failures:0,errors:0});else{b=u;break}}return y.slice(0,b)}getDaysInUTCMonth(e){return new Date(e.getUTCFullYear(),e.getUTCMonth()+1,0).getUTCDate()}createUsageLineCharts(e,t){let i={legend:"Successes",label:"${"+S.DewPoint+"} successes",type:S.DewPoint,values:e.map(h=>({x:h.epochMs+t,y:h.successes}
2))},l={legend:"Failures",label:"${"+S.Temperature+"} failures",type:S.Temperature,values:e.map(h=>({x:h.epochMs+t,y:h.failures}))},T={legend:"Errors",label:"${"+S.Pressure+"} errors",type:S.Pressure,values:e.map(h=>({x:h.epochMs+t,y:h.errors}))};return{[z.Line]:[i,l,T]}}previousDate(){this.modifyKeyPending||(this.modifyKeyPending=!0,this.currentGraphDate=this.changeUsageDate(this.currentGraphDate,this.currentGraphType,-1),this.setUsageGraph(this.apiKey,this.currentGraphType,this.currentGraphDate))}nextDate(){this.modifyKeyPending||(this.modifyKeyPending=!0,this.currentGraphDate=this.changeUsageDate(this.currentGraphDate,this.currentGraphType,1),this.setUsageGraph(this.apiKey,this.currentGraphType,this.currentGraphDate))}changeUsageDate(e,t,i){let l=new Date(e.getTime());switch(t){case K.DAY:{l.setUTCMonth(e.getUTCMonth()+i);break}case K.HOUR:{l.setUTCDate(e.getUTCDate()+i);break}default:throw new Error("Unsupported graph type "+t)}return l}static{this.\u0275fac=function(t){return new(t||n)(v(B),v(O),v(V),v(X))}}static{this.\u0275cmp=F({type:n,selectors:[["app-api-keys"]],decls:13,vars:3,consts:[[1,"region-content-top"],[1,"row"],[1,"columns"],["for","apiKeyField"],["href","/pws/overview",1,"button"],["id","apiKeyField","disabled","",3,"type","value"],[1,"tos"],["id","tos","type","checkbox","formControlName","tos","name","tos",3,"change","checked"],["for","tos",1,"checkbox"],["href","/company/legal","target","_blank","rel","noreferer noopener"],[1,"text-right","error-text"],[1,"button",3,"click","disabled"],[1,"small-12","medium-6","columns"],[1,"key-options","row","collapse"],[1,"small-6","columns"],[1,"button",3,"click"],[1,"hide-show",3,"click"],[1,"callout","secondary"],["href","https://docs.google.com/document/d/1eKCnKXI9xnoMGRRzOL1xPCBihNV2rOet08qpE_gArAY","target","_blank","rel","noreferer noopener",1,"button"],[1,"usage-graph"],["id","usageGraph",3,"data"]],template:function(t,i){t&1&&(s(0,"one-column-layout")(1,"div",0)(2,"div",1)(3,"div",2),P(4,"app-subnav"),o()()(),s(5,"div",1)(6,"div",2)(7,"label",3)(8,"h2"),r(9,"Your API Key"),o()(),x(10,xe,4,3,"div")(11,Ce,3,0,"div")(12,Te,3,0,"div"),o()()()),t&2&&(a(10),c(i.profileLoaded&&i.profileLoadSuccess?10:-1),a(),c(i.profileLoaded&&!i.profileLoadSuccess?11:-1),a(),c(i.profileLoaded?-1:12))},dependencies:[te,q,ee,I],styles:["#apiKeyField[_ngcontent-%COMP%]{font-family:Courier New,Courier,monospace}#apiKeyField[_ngcontent-%COMP%], .key-options[_ngcontent-%COMP%], .tos[_ngcontent-%COMP%]{max-width:500px;margin-bottom:20px}.key-options[_ngcontent-%COMP%] .button[_ngcontent-%COMP%]{float:left}.hide-show[_ngcontent-%COMP%]{color:#006f9e;text-decoration:underline;float:right}.error-text[_ngcontent-%COMP%]{color:#d5202a;display:inline-block;font-size:.675rem}.usage-graph[_ngcontent-%COMP%]{border-top:1px solid #D7D7D7;padding:20px 0;margin-top:20px}"]})}}return n})();export{Ye as ApiKeysComponent};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.