@vouchfor/embeds 0.0.0-experiment.bdda3d0 → 0.0.0-experiment.cb30cc7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/embeds",
3
- "version": "0.0.0-experiment.bdda3d0",
3
+ "version": "0.0.0-experiment.cb30cc7",
4
4
  "license": "MIT",
5
5
  "author": "Aaron Williams",
6
6
  "main": "dist/es/embeds.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@lit/task": "1.0.0",
39
- "@vouchfor/media-player": "0.0.0-experiment.bdda3d0",
39
+ "@vouchfor/media-player": "0.0.0-experiment.cb30cc7",
40
40
  "uuid": "^9.0.1"
41
41
  },
42
42
  "peerDependencies": {
@@ -1,7 +1,6 @@
1
1
  import { Task } from '@lit/task';
2
2
 
3
3
  import type { Embed, EmbedProps } from '..';
4
- import type { TemplateInstance } from '@vouchfor/canvas-video';
5
4
  import type { ReactiveControllerHost } from 'lit';
6
5
  import type { Environment } from '~/utils/env';
7
6
 
@@ -21,8 +20,6 @@ class FetcherController {
21
20
  host: EmbedHost;
22
21
 
23
22
  private _fetching = false;
24
- private _vouch?: EmbedProps['data'];
25
- private _template?: TemplateInstance;
26
23
 
27
24
  set fetching(value) {
28
25
  if (this._fetching !== value) {
@@ -34,50 +31,22 @@ class FetcherController {
34
31
  return this._fetching;
35
32
  }
36
33
 
37
- set vouch(value) {
38
- if (this._vouch !== value) {
39
- this._vouch = value;
40
- this.host.requestUpdate();
41
- }
42
- }
43
- get vouch() {
44
- return this._vouch;
45
- }
46
-
47
- set template(value) {
48
- if (this._template !== value) {
49
- this._template = value;
50
- this.host.requestUpdate();
51
- }
52
- }
53
- get template() {
54
- return this._template;
55
- }
56
-
57
- private async getVouch(env: Environment, apiKey: string, vouchId?: string) {
34
+ private async getVouch(env: Environment, apiKey: string, vouchId: string) {
58
35
  const { embedApiUrl } = getEnvUrls(env);
59
36
 
60
- if (vouchId) {
61
- return fetch(`${embedApiUrl}/vouches/${vouchId}`, {
62
- method: 'GET',
63
- headers: [['X-Api-Key', apiKey]]
64
- }).then((response) => response.json());
65
- }
66
-
67
- return null;
37
+ return fetch(`${embedApiUrl}/vouches/${vouchId}`, {
38
+ method: 'GET',
39
+ headers: [['X-Api-Key', apiKey]]
40
+ }).then((response) => response.json());
68
41
  }
69
42
 
70
- private async getTemplate(env: Environment, apiKey: string, templateId?: string) {
43
+ private async getTemplate(env: Environment, apiKey: string, templateId: string) {
71
44
  const { embedApiUrl } = getEnvUrls(env);
72
45
 
73
- if (templateId) {
74
- return fetch(`${embedApiUrl}/templates/${templateId}`, {
75
- method: 'GET',
76
- headers: [['X-Api-Key', apiKey]]
77
- }).then((response) => response.json());
78
- }
79
-
80
- return null;
46
+ return fetch(`${embedApiUrl}/templates/${templateId}`, {
47
+ method: 'GET',
48
+ headers: [['X-Api-Key', apiKey]]
49
+ }).then((response) => response.json());
81
50
  }
82
51
 
83
52
  constructor(host: EmbedHost) {
@@ -86,22 +55,26 @@ class FetcherController {
86
55
  this.host,
87
56
  async ([env, apiKey, data, vouchId, templateId]: TaskDeps) => {
88
57
  try {
89
- this.vouch = undefined;
90
- this.template = undefined;
58
+ host.vouch = undefined;
59
+ host.template = undefined;
91
60
 
92
61
  if (data) {
93
- const template = await this.getTemplate(env, apiKey, templateId);
94
- this.vouch = data;
95
- this.template = data?.settings?.template?.instance ?? template;
62
+ let template;
63
+ if (templateId) {
64
+ this.fetching = true;
65
+ template = await this.getTemplate(env, apiKey, templateId);
66
+ }
67
+ host.vouch = data;
68
+ host.template = template ?? data?.settings?.template?.instance;
96
69
  } else if (vouchId) {
97
70
  this.fetching = true;
98
71
 
99
72
  const [vouch, template] = await Promise.all([
100
73
  this.getVouch(env, apiKey, vouchId),
101
- this.getTemplate(env, apiKey, templateId)
74
+ templateId ? this.getTemplate(env, apiKey, templateId) : null
102
75
  ]);
103
- this.vouch = vouch;
104
- this.template = vouch?.settings?.template?.instance ?? template;
76
+ host.vouch = vouch;
77
+ host.template = template ?? vouch?.settings?.template?.instance;
105
78
  }
106
79
  } finally {
107
80
  this.fetching = false;
@@ -1,5 +1,5 @@
1
1
  import { html, LitElement } from 'lit';
2
- import { customElement, property } from 'lit/decorators.js';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
3
  import { ifDefined } from 'lit/directives/if-defined.js';
4
4
  import { createRef, ref } from 'lit/directives/ref.js';
5
5
 
@@ -69,13 +69,8 @@ class Embed extends LitElement {
69
69
  // @ts-ignore
70
70
  private _trackingController = new TrackingController(this);
71
71
 
72
- get vouch() {
73
- return this._fetcherController.vouch;
74
- }
75
-
76
- get template(): TemplateInstance | undefined {
77
- return this._fetcherController.template;
78
- }
72
+ @state() vouch: EmbedProps['data'];
73
+ @state() template: TemplateInstance | undefined;
79
74
 
80
75
  get fetching() {
81
76
  return this._fetcherController.fetching;