@vouchfor/embeds 0.0.0-experiment.88ebbc0 → 0.0.0-experiment.8b3403f

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/embeds",
3
- "version": "0.0.0-experiment.88ebbc0",
3
+ "version": "0.0.0-experiment.8b3403f",
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.88ebbc0",
39
+ "@vouchfor/media-player": "0.0.0-experiment.8b3403f",
40
40
  "uuid": "^9.0.1"
41
41
  },
42
42
  "peerDependencies": {
@@ -31,23 +31,48 @@ class FetcherController {
31
31
  return this._fetching;
32
32
  }
33
33
 
34
- private async getVouch(env: Environment, apiKey: string, vouchId: string) {
34
+ private getVouch = async (env: Environment, apiKey: string, vouchId: string) => {
35
35
  const { embedApiUrl } = getEnvUrls(env);
36
36
 
37
- return fetch(`${embedApiUrl}/vouches/${vouchId}`, {
37
+ const vouch = await fetch(`${embedApiUrl}/vouches/${vouchId}`, {
38
38
  method: 'GET',
39
39
  headers: [['X-Api-Key', apiKey]]
40
- }).then((response) => response.json());
41
- }
40
+ }).then((response) => {
41
+ this.host.dispatchEvent(new CustomEvent('vouch:loaded', { detail: vouchId }));
42
+ return response.json();
43
+ });
44
+
45
+ // HACK: trigger another fetch after we received the data to update the cache in the background
46
+ fetch(`${embedApiUrl}/vouches/${vouchId}`, {
47
+ method: 'GET',
48
+ headers: [
49
+ ['X-Api-Key', apiKey],
50
+ ['Cache-Control', 'max-age=0']
51
+ ]
52
+ });
53
+
54
+ return vouch;
55
+ };
42
56
 
43
- private async getTemplate(env: Environment, apiKey: string, templateId: string) {
57
+ private getTemplate = async (env: Environment, apiKey: string, templateId: string) => {
44
58
  const { embedApiUrl } = getEnvUrls(env);
45
59
 
46
- return fetch(`${embedApiUrl}/templates/${templateId}`, {
60
+ const template = await fetch(`${embedApiUrl}/templates/${templateId}`, {
47
61
  method: 'GET',
48
62
  headers: [['X-Api-Key', apiKey]]
49
63
  }).then((response) => response.json());
50
- }
64
+
65
+ // HACK: trigger another fetch after we received the data to update the cache in the background
66
+ fetch(`${embedApiUrl}/templates/${templateId}`, {
67
+ method: 'GET',
68
+ headers: [
69
+ ['X-Api-Key', apiKey],
70
+ ['Cache-Control', 'max-age=0']
71
+ ]
72
+ });
73
+
74
+ return template;
75
+ };
51
76
 
52
77
  constructor(host: EmbedHost) {
53
78
  this.host = host;
@@ -116,7 +116,7 @@ class TrackingController implements ReactiveController {
116
116
  });
117
117
 
118
118
  return {
119
- source: 'media_player',
119
+ source: this.host.trackingSource,
120
120
  time: new Date(),
121
121
  region,
122
122
  country,
@@ -17,6 +17,7 @@ import '@vouchfor/media-player';
17
17
  type EmbedProps = Pick<MediaPlayerProps, 'data' | 'aspectRatio' | 'preload' | 'autoplay' | 'controls'> & {
18
18
  env: Environment;
19
19
  apiKey: string;
20
+ trackingSource?: string;
20
21
  vouchId?: string;
21
22
  templateId?: string;
22
23
  };
@@ -31,6 +32,7 @@ class Embed extends LitElement {
31
32
 
32
33
  @property({ type: String }) env: EmbedProps['env'] = 'prod';
33
34
  @property({ type: String }) apiKey: EmbedProps['apiKey'] = '';
35
+ @property({ type: String }) trackingSource: EmbedProps['trackingSource'] = 'embed';
34
36
 
35
37
  @property({ type: Array }) controls: EmbedProps['controls'];
36
38
  @property({ type: String }) preload: EmbedProps['preload'] = 'auto';