Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 2436e42

Browse files
committed
fix: shared types, duplicated types
1 parent bbded0c commit 2436e42

File tree

16 files changed

+77
-79
lines changed

16 files changed

+77
-79
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 ydennisy
3+
Copyright (c) 2020 AirGrid LTD
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+20-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
EdgeKit.org -> https://projects.invisionapp.com/share/2NXLNZYG64X#/screens/421377757
66

77
## Features:
8+
89
> (this needs some sections....)
910
1011
- Packaged with a taxonomy of [IAB Data Transparency Framework](https://iabtechlab.com/standards/data-transparency/) audiences.
@@ -23,18 +24,21 @@ EdgeKit.org -> https://projects.invisionapp.com/share/2NXLNZYG64X#/screens/42137
2324
### Install
2425

2526
First we install EdgeKit into our project.
27+
2628
```shell
2729
$ npm i -S @AirGrid/EdgeKit
2830
```
2931

3032
We can now import the API into our script.
33+
3134
```javascript
3235
import edkt from '@AirGrid/EdgeKit';
3336
```
3437

3538
Alternatively to get started quickly, we can use unpkg to load the `edkt` object into the `window`.
39+
3640
```html
37-
<Todo>
41+
<Todo></Todo>
3842
```
3943

4044
### Page Features
@@ -47,10 +51,10 @@ A simple example would be to collect the keywords often present in the meta tags
4751
<!DOCTYPE html>
4852
<html lang="en">
4953
<head>
50-
<meta charset="UTF-8">
51-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
52-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
53-
<meta name="keywords" content="sport,news,football,stadium">
54+
<meta charset="UTF-8" />
55+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
56+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
57+
<meta name="keywords" content="sport,news,football,stadium" />
5458
<title>Article about sports, news and football!</title>
5559
</head>
5660
<body>
@@ -69,28 +73,32 @@ const getPageKeywords = {
6973
const keywordString = tag.getAttribute('content');
7074
const keywords = keywordString.toLowerCase().split(',');
7175
return Promise.resolve(keywords);
72-
}
73-
}
76+
},
77+
};
7478
```
7579

7680
### Init
7781

7882
Now we can initialise and run the library passing in `pageFeatureGetters`, which will:
83+
7984
1. Collect and store all the features which correspond to this page view event (current page).
8085
2. Evaluate all the audience model definitions, to see if the user can be added into any new `elegibleAudiences`.
8186
3. Pass this information to Prebid, for any subsequent ad calls on the same page.
8287

8388
```javascript
8489
edkt.init({
85-
pageFeatureGetters: pageFeatureGetters
90+
pageFeatureGetters: pageFeatureGetters,
8691
});
8792
```
8893

8994
### Prebid
95+
9096
> this makes sense to be last in the readme, but it must occur first in the actual page code.
9197
9298
Now we can use EdgeKit to grab and pass audience IDs, from the device into Prebid for downstream targeting. This must happen early in the execution of the page before Prebid makes bid requests to adapters.
9399

100+
> todo: we need to add links to the prebid docs here to explain the below object.
101+
94102
```javascript
95103
const edktAudienceIds = edkt.getElegibleAudienceIds();
96104

@@ -104,10 +112,10 @@ pbjs.que.push(() => {
104112
user: {
105113
data: {
106114
user: edktAudienceIds,
107-
}
108-
}
109-
}
110-
}
115+
},
116+
},
117+
},
118+
},
111119
});
112120
});
113121
```

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"scripts": {
55
"build": "tsc -b packages",
6+
"watch": "tsc -w packages",
67
"lint": "eslint packages/**/src packages/**/__test__ --ext js,ts",
78
"lint:fix": "eslint packages/**/src packages/**/__test__ --ext js,ts --fix"
89
},

packages/audiences/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
},
1010
"author": "ydennisy",
1111
"license": "MIT",
12+
"dependencies": {
13+
"@edgekit/types": "^0.0.1"
14+
},
1215
"devDependencies": {
1316
"typescript": "^3.9.5"
1417
}

packages/audiences/src/definitions/interest/sport.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const condition = {
1+
import { ICondition } from '@edgekit/types';
2+
3+
const condition: ICondition = {
24
filter: {
35
queries: [
46
{
@@ -10,10 +12,10 @@ const condition = {
1012
rules: [
1113
{
1214
reducer: {
13-
name: 'count' as const,
15+
name: 'count',
1416
},
1517
matcher: {
16-
name: 'gt' as const,
18+
name: 'gt',
1719
args: 1,
1820
},
1921
},

packages/audiences/src/definitions/interest/travel.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const condition = {
1+
import { ICondition } from '@edgekit/types';
2+
3+
const condition: ICondition = {
24
filter: {
35
queries: [
46
{
@@ -10,10 +12,10 @@ const condition = {
1012
rules: [
1113
{
1214
reducer: {
13-
name: 'count' as const,
15+
name: 'count',
1416
},
1517
matcher: {
16-
name: 'gt' as const,
18+
name: 'gt',
1719
args: 2,
1820
},
1921
},

packages/core/src/features/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// TODO: this is duplicated - move into types.
2-
interface IPageFeatureGetter {
3-
name: string;
4-
func: () => Promise<string[]>;
5-
}
1+
import { IPageFeatureGetter } from '../types';
62

73
const wrapPageFeatureGetters = (pageFeatureGetters: IPageFeatureGetter[]) => {
84
return pageFeatureGetters.map((getter) => {

packages/core/src/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ import audiences from '@edgekit/audiences';
33
import { getPageFeatures } from './features';
44
import { viewStore, audienceStore } from './store';
55
import { timeStampInSecs } from './utils';
6+
import { IPageFeatureGetter } from './types';
67

78
interface IConfig {
89
pageFeatureGetters: IPageFeatureGetter[];
910
}
1011

11-
interface IPageFeatureGetter {
12-
name: string;
13-
func: () => Promise<string[]>;
14-
}
15-
1612
// TODO: we need to give a way to consumers to ensure this does not
1713
// run multiple times on a single page load.
1814
const run = async (config: IConfig): Promise<void> => {

packages/core/src/store/audience.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { storage, timeStampInSecs } from '../utils';
2-
3-
enum StorageKeys {
4-
PAGE_VIEWS = 'edkt_page_views',
5-
MATCHED_AUDIENCES = 'edkt_matched_audiences',
6-
MATCHED_AUDIENCE_IDS = 'edkt_matched_audience_ids',
7-
}
2+
import { StorageKeys } from '../types';
83

94
interface IMatchedAudience {
105
id: string;
@@ -13,7 +8,6 @@ interface IMatchedAudience {
138
matchedOnCurrentPageView: boolean;
149
}
1510

16-
// TODO: share the types.
1711
class AudienceStore {
1812
matchedAudiences: IMatchedAudience[];
1913
matchedAudienceIds: string[];

packages/core/src/store/pageview.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { IPageView } from '@edgekit/types';
22
import { storage, timeStampInSecs } from '../utils';
3-
4-
enum StorageKeys {
5-
PAGE_VIEWS = 'edkt_page_views',
6-
MATCHED_AUDIENCES = 'edkt_matched_audiences',
7-
MATCHED_AUDIENCE_IDS = 'edkt_matched_audience_ids',
8-
}
3+
import { StorageKeys } from '../types';
94

105
interface IPageFeature {
116
name: string;

packages/core/src/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface IPageFeatureGetter {
2+
name: string;
3+
func: () => Promise<string[]>;
4+
}
5+
6+
export enum StorageKeys {
7+
PAGE_VIEWS = 'edkt_page_views',
8+
MATCHED_AUDIENCES = 'edkt_matched_audiences',
9+
MATCHED_AUDIENCE_IDS = 'edkt_matched_audience_ids',
10+
}

packages/engine/src/condition.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { IPageView } from '@edgekit/types';
1+
import { IPageView, ICondition } from '@edgekit/types';
22
import * as reducers from './reducers';
33
import * as matchers from './matchers';
4-
import { ICondition } from './types';
54

65
const createCondition = (condition: ICondition) => (pageViews: IPageView[]) => {
76
const { filter, rules } = condition;

packages/engine/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { IPageView, ICondition } from '@edgekit/types';
12
import createCondition from './condition';
2-
import { IPageView, ICondition } from './types';
33

44
export const check = (
55
conditions: ICondition[],

packages/engine/src/reducers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPageView } from './types';
1+
import { IPageView } from '@edgekit/types';
22

33
export const count = () => (pageViews: IPageView[]): number => pageViews.length;
44

packages/engine/src/types.ts

-33
This file was deleted.

packages/types/src/index.ts

+25
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,28 @@ export interface IPageView {
44
[name: string]: string[];
55
};
66
}
7+
8+
export interface IConditionQuery {
9+
property: string;
10+
value: string[] | number[];
11+
}
12+
13+
export interface IConditionRule {
14+
reducer: {
15+
name: 'count';
16+
// args?: string;
17+
};
18+
matcher: {
19+
name: 'eq' | 'gt' | 'lt' | 'ge' | 'le';
20+
args: number;
21+
};
22+
}
23+
24+
export interface ICondition {
25+
filter: {
26+
// TODO: return support for any?
27+
// any: boolean;
28+
queries: IConditionQuery[];
29+
};
30+
rules: IConditionRule[];
31+
}

0 commit comments

Comments
 (0)