@pb33f/cowboy-components 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { LitElement } from "lit";
2
2
  import { SlDialog } from "@shoelace-style/shoelace";
3
- import { OAuthLogin } from "./oauth-login";
3
+ import { OAuthLogin } from "./oauth-login.js";
4
4
  export declare class LoginButton extends LitElement {
5
5
  static styles: import("lit").CSSResult[];
6
6
  authDialog: SlDialog;
@@ -8,11 +8,13 @@ export declare class LoginButton extends LitElement {
8
8
  buttonLabel: string;
9
9
  redirectUrl: string;
10
10
  textLink: boolean;
11
+ stateCheck: boolean;
11
12
  oauthLogin: OAuthLogin;
12
13
  private controller;
13
14
  constructor();
15
+ protected firstUpdated(): void;
14
16
  updated(): void;
15
- render(): import("lit-html").TemplateResult<1>;
17
+ render(): import("lit-html").TemplateResult<1> | null;
16
18
  anonView(): import("lit-html").TemplateResult<1>;
17
19
  hide(): void;
18
20
  authenticatedView(): import("lit-html").TemplateResult<1>;
@@ -6,13 +6,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { html, LitElement } from "lit";
8
8
  import { customElement, property, query } from "lit/decorators.js";
9
- import { AuthController } from "../../controllers/auth-controller";
10
- import buttonCss from "../../css/button.css";
11
- import modalCss from "../../css/modal.css";
12
- import loginButtonCss from "./login-button.css";
13
- import tooltipCss from "../../css/tooltip.css";
14
- import { LogoutRequested } from "../../events/doctor";
15
- import linksCss from "../../css/links.css";
9
+ import { AuthController } from "../../controllers/auth-controller.js";
10
+ import buttonCss from "../../css/button.css.js";
11
+ import modalCss from "../../css/modal.css.js";
12
+ import loginButtonCss from "./login-button.css.js";
13
+ import tooltipCss from "../../css/tooltip.css.js";
14
+ import { LogoutRequested } from "../../events/doctor.js";
15
+ import linksCss from "../../css/links.css.js";
16
16
  let LoginButton = class LoginButton extends LitElement {
17
17
  constructor() {
18
18
  super();
@@ -21,6 +21,18 @@ let LoginButton = class LoginButton extends LitElement {
21
21
  this.buttonLabel = 'Authenticate';
22
22
  this.redirectUrl = '';
23
23
  this.textLink = false;
24
+ this.stateCheck = false;
25
+ }
26
+ firstUpdated() {
27
+ if (this.stateCheck) {
28
+ this.controller.checkState().then(() => {
29
+ this.stateCheck = false;
30
+ this.requestUpdate();
31
+ }).finally(() => {
32
+ this.stateCheck = false;
33
+ this.requestUpdate();
34
+ });
35
+ }
24
36
  }
25
37
  updated() {
26
38
  if (this.oauthLogin) {
@@ -28,6 +40,9 @@ let LoginButton = class LoginButton extends LitElement {
28
40
  }
29
41
  }
30
42
  render() {
43
+ if (this.stateCheck) {
44
+ return null;
45
+ }
31
46
  let out = this.anonView();
32
47
  if (this.controller.authenticated) {
33
48
  out = this.authenticatedView();
@@ -106,6 +121,9 @@ __decorate([
106
121
  __decorate([
107
122
  property({ type: Boolean })
108
123
  ], LoginButton.prototype, "textLink", void 0);
124
+ __decorate([
125
+ property({ type: Boolean })
126
+ ], LoginButton.prototype, "stateCheck", void 0);
109
127
  __decorate([
110
128
  query('pb33f-oauth-login')
111
129
  ], LoginButton.prototype, "oauthLogin", void 0);
@@ -1,5 +1,5 @@
1
1
  import { LitElement } from "lit";
2
- import { AuthController } from "../../controllers/auth-controller";
2
+ import { AuthController } from "../../controllers/auth-controller.js";
3
3
  export declare class LoginPanel extends LitElement {
4
4
  static styles: import("lit").CSSResult[];
5
5
  title: string;
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { html, LitElement } from "lit";
8
8
  import { customElement, property } from "lit/decorators.js";
9
- import loginButtonCss from "./login-button.css";
9
+ import loginButtonCss from "./login-button.css.js";
10
10
  let LoginPanel = class LoginPanel extends LitElement {
11
11
  constructor() {
12
12
  super();
@@ -1,7 +1,7 @@
1
1
  import { LitElement } from "lit";
2
2
  import '../electric-box/electric-box.js';
3
3
  import { SlAnimation, SlButton } from "@shoelace-style/shoelace";
4
- import { ElectricBox } from "../electric-box/electric-box";
4
+ import { ElectricBox } from "../electric-box/electric-box.js";
5
5
  export declare class OAuthLogin extends LitElement {
6
6
  static styles: import("lit").CSSResult[];
7
7
  title: string;
@@ -6,10 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { html, LitElement } from "lit";
8
8
  import { customElement, property, query, state } from "lit/decorators.js";
9
- import oauthLoginCss from "./oauth-login.css";
10
- import buttonCss from "../../css/button.css";
9
+ import oauthLoginCss from "./oauth-login.css.js";
10
+ import buttonCss from "../../css/button.css.js";
11
11
  import '../electric-box/electric-box.js';
12
- import { AuthenticationGithubRequested } from "../../events/doctor";
12
+ import { AuthenticationGithubRequested } from "../../events/doctor.js";
13
13
  let OAuthLogin = class OAuthLogin extends LitElement {
14
14
  constructor() {
15
15
  super();
@@ -9,8 +9,8 @@ import { html, LitElement } from "lit";
9
9
  import buttonCss from "../../css/button.css.js";
10
10
  import statusBarCss from "./status-bar.css.js";
11
11
  import linksCss from "../../css/links.css.js";
12
- import dialogCss from "../../css/dialog.css";
13
- import { OpenAuthentication } from "../../events/doctor";
12
+ import dialogCss from "../../css/dialog.css.js";
13
+ import { OpenAuthentication } from "../../events/doctor.js";
14
14
  let StatusBar = class StatusBar extends LitElement {
15
15
  constructor() {
16
16
  super();
@@ -50,7 +50,7 @@ let StatusBar = class StatusBar extends LitElement {
50
50
  return html `
51
51
  <div class="status-bar ${clazz}">
52
52
  <sl-dialog label="Purchase Credit" class="dialog-overview">
53
- <p>Still working on this, coming soon!
53
+ <p>Still working on this, coming soon! Come back tomorrow for more free credit.
54
54
  </p>
55
55
  <sl-button slot="footer" variant="primary" @click="${this.closeDialog}">Close</sl-button>
56
56
  </sl-dialog>
@@ -200,6 +200,7 @@ let TheDoctor = class TheDoctor extends LitElement {
200
200
  };
201
201
  // create auth controller
202
202
  this.authController = new AuthController(this, sessionCallback, true);
203
+ this.authController.start();
203
204
  // listen for auth state changes.
204
205
  //@ts-ignore
205
206
  this.addEventListener(EditorUpdated, this.specController.specChanged.bind(this.specController));
@@ -14,6 +14,7 @@ export declare class AuthController extends EventTarget {
14
14
  brokerStarted: boolean;
15
15
  hosts: any[];
16
16
  callbackIdx: number;
17
+ checkingState: boolean;
17
18
  constructor(host: any, sessionCallback?: Function, autoStart?: boolean);
18
19
  start(): void;
19
20
  private startSession;
@@ -1,6 +1,6 @@
1
1
  import { AuthenticationGithubRequested, AuthenticationStateChange, CreditEmpty, LogoutRequested, NukeWorkspaceEvent, StartSessionFailed } from "../events/doctor.js";
2
2
  import { AuthService } from "../services/auth-service.js";
3
- import { HeaderService } from "../services/header-service";
3
+ import { HeaderService } from "../services/header-service.js";
4
4
  export class AuthController extends EventTarget {
5
5
  static getInstance() {
6
6
  const t = AuthController._instance;
@@ -20,9 +20,10 @@ export class AuthController extends EventTarget {
20
20
  }
21
21
  t.startSessionAutomatically = autoStart;
22
22
  t.brokerStarted = false;
23
- t.start();
23
+ // t.start()
24
24
  return t;
25
25
  }
26
+ this.checkingState = false;
26
27
  this.doctorEndpoint = 'https://doctor.pb33f.io';
27
28
  const sessionEndpoint = sessionStorage.getItem("doctor-endpoint");
28
29
  if (sessionEndpoint) {
@@ -138,7 +139,6 @@ export class AuthController extends EventTarget {
138
139
  }
139
140
  logout() {
140
141
  AuthService.logout().then(() => {
141
- //if (e.detail.redirectURL != '') {
142
142
  this.dispatchEvent(new CustomEvent(NukeWorkspaceEvent, {
143
143
  bubbles: true,
144
144
  composed: true,
@@ -146,20 +146,38 @@ export class AuthController extends EventTarget {
146
146
  resetFiles: true
147
147
  }
148
148
  }));
149
- // }
150
149
  });
151
150
  }
152
151
  notifyStateChange(state) {
152
+ this.checkingState = false;
153
153
  const event = new CustomEvent(AuthenticationStateChange, {
154
154
  detail: { state }
155
155
  });
156
156
  this.dispatchEvent(event);
157
157
  }
158
158
  async checkState() {
159
- return AuthService.checkAuth().then(state => {
160
- this.notifyStateChange(state);
161
- return state;
162
- });
159
+ if (!this.checkingState) {
160
+ this.checkingState = true;
161
+ return AuthService.checkAuth()
162
+ .then(state => {
163
+ this.state = state;
164
+ this.authenticated = true;
165
+ this.notifyStateChange(state);
166
+ return state;
167
+ })
168
+ .catch(error => {
169
+ this.notifyStateChange();
170
+ this.checkingState = false;
171
+ throw error;
172
+ });
173
+ }
174
+ else {
175
+ return new Promise((resolve) => {
176
+ this.addEventListener(AuthenticationStateChange, ((event) => {
177
+ resolve(event.detail.state);
178
+ }), { once: true });
179
+ });
180
+ }
163
181
  }
164
182
  }
165
183
  AuthController._instance = null;
@@ -237,11 +237,15 @@ export class DiagnosticController extends EventTarget {
237
237
  if (e.instance === 'https://pb33f.io/errors/no-credit-remaining') {
238
238
  this.doc.statusBar.callsRemaining = 0;
239
239
  this.doc.statusBar.visible = true;
240
+ let text = "Run out of credit, please authenticate for more or wait 24 hours.";
241
+ if (this.doc.authController.authenticated) {
242
+ text = "Run out of credit, please purchase more, or come back tomorrow for more free credits.";
243
+ }
240
244
  this.doc.sendToast({
241
245
  id: crypto.randomUUID(),
242
246
  type: ToastType.ERROR,
243
- body: "Run out of credit, please authenticate for more or wait 24 hours.",
244
- title: "Credit exhausted!",
247
+ body: text,
248
+ title: "💰 Credit Exhausted!",
245
249
  });
246
250
  }
247
251
  else {
@@ -1,4 +1,4 @@
1
- import { DocumentationExpirationBag, FunctionDocumentationBag, RuleDocumentationBag } from "../components/the-doctor/the-doctor";
1
+ import { FunctionDocumentationBag, RuleDocumentationBag } from "../components/the-doctor/the-doctor";
2
2
  import { LintingService } from "../services/linting-service";
3
3
  import { ProblemDrawerEventType } from "../components/problem-list/details-drawer";
4
4
  import { ToastType } from "../model/toast";
@@ -8,7 +8,13 @@ export class DocsController extends EventTarget {
8
8
  this.doc = doc;
9
9
  }
10
10
  fetchDocs() {
11
- //return;
11
+ const db = this.doc.bagManager.getBag(RuleDocumentationBag);
12
+ const fb = this.doc.bagManager.getBag(FunctionDocumentationBag);
13
+ this.doc.ruleDocsBag = db;
14
+ this.doc.functionDocsBag = fb;
15
+ if ((fb?.export().size ?? 0 > 0) && (db?.export().size ?? 0 > 0)) {
16
+ return;
17
+ }
12
18
  this.doc.activitySpinner.show();
13
19
  const url = new URL(window.location.href);
14
20
  const urlParam = url.searchParams.get('url');
@@ -27,8 +33,6 @@ export class DocsController extends EventTarget {
27
33
  this.doc.platformUnavailable(e);
28
34
  console.error("documentation service is down");
29
35
  });
30
- this.doc.ruleDocsBag = this.doc.bagManager.getBag(RuleDocumentationBag);
31
- this.doc.functionDocsBag = this.doc.bagManager.getBag(FunctionDocumentationBag);
32
36
  // populate docs via worker.
33
37
  this.doc.ruleDocsWorker.addEventListener("message", (event) => {
34
38
  const data = event.data;
@@ -44,14 +48,6 @@ export class DocsController extends EventTarget {
44
48
  this.doc.activitySpinner.hide();
45
49
  }
46
50
  });
47
- // let ruleDocs: string[] = [];
48
- // let functionDocs: string[] = [];
49
- // if (this.ruleDocsBag) {
50
- // ruleDocs = Array.from(this.ruleDocsBag.export().keys());
51
- // }
52
- // if (this.functionDocsBag) {
53
- // functionDocs = Array.from(this.functionDocsBag.export().keys());
54
- // }
55
51
  const fetchDocs = () => {
56
52
  this.doc.ruleDocsWorker.postMessage({
57
53
  start: true,
@@ -60,27 +56,7 @@ export class DocsController extends EventTarget {
60
56
  existingFunctions: []
61
57
  });
62
58
  };
63
- // check expiration
64
- if (this.doc.docExpirationBag) {
65
- const expiration = this.doc.docExpirationBag.get(DocumentationExpirationBag);
66
- // if the docs are older than 15 days, refresh them.
67
- if (expiration) {
68
- const now = new Date().getTime();
69
- const then = new Date(expiration).getTime();
70
- // if (now - then > 1296000000) {
71
- // fetchDocs();
72
- // } else {
73
- // this.activitySpinner.hide();
74
- // }
75
- fetchDocs(); // always fetch for now.
76
- }
77
- else {
78
- fetchDocs();
79
- }
80
- }
81
- else {
82
- fetchDocs();
83
- }
59
+ fetchDocs();
84
60
  }
85
61
  ruleDocsClicked(event) {
86
62
  const ruleId = event.detail.rule;