Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wit #4

Merged
merged 8 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @edgee-cloud/edgeers
31 changes: 31 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and Deploy

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'

- name: Install dependencies
run: npm install

- name: Run build
run: npm run build

- name: Run tests
run: npm test
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
/coverage

# Build artifacts
*.wasm

# Misc
.*
!.gitignore
*.wasm
27 changes: 14 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const buildEdgeeRequest = (payload, apiKey) => ({
["Authorization", `Bearer ${apiKey}`],
],
body: JSON.stringify(payload),
forwardClientHeaders: true,
});

/**
Expand Down Expand Up @@ -101,58 +102,58 @@ export const dataCollection = {

/**
* @param {Event} e
* @param {Dict} cred
* @param {Dict} settings
*/
page(e, cred) {
page(e, settings) {
if (e.data.tag != 'page') {
throw new Error("Missing page data");
}

// convert to native object
cred = convertDict(cred);
settings = convertDict(settings);

// build payload
const payload = buildPagePayload(e.data.val, e.context);

// build and return EdgeeRequest
return buildEdgeeRequest(payload, cred['your_api_key']);
return buildEdgeeRequest(payload, settings['your_api_key']);
},

/**
* @param {Event} e
* @param {Dict} cred
* @param {Dict} settings
*/
track(e, cred) {
track(e, settings) {
if (e.data.tag != 'track') {
throw new Error("Missing track data");
}

// convert to native object
cred = convertDict(cred);
settings = convertDict(settings);

// build payload
const payload = buildTrackPayload(e.data.val, e.context);

// build and return EdgeeRequest
return buildEdgeeRequest(payload, cred['your_api_key']);
return buildEdgeeRequest(payload, settings['your_api_key']);
},

/**
* @param {Event} e
* @param {Dict} cred
* @param {Dict} settings
*/
user(e, cred) {
user(e, settings) {
if (e.data.tag != 'user') {
throw new Error("Missing user data");
}

// convert to native object
cred = convertDict(cred);
settings = convertDict(settings);

// build payload
const payload = buildUserPayload(e.data.val, e.context);

// build and return EdgeeRequest
return buildEdgeeRequest(payload, cred['your_api_key']);
return buildEdgeeRequest(payload, settings['your_api_key']);
},
};
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ describe('data collection component', function () {
consent: "granted",
};

const sampleCreds = [
const sampleSettings = [
["your_api_key", "api_value"]
];

describe('#page()', function () {
it('should return an EdgeeRequest object', function () {
const req = dataCollection.page(samplePageEvent, sampleCreds);
const req = dataCollection.page(samplePageEvent, sampleSettings);
assert.equal(req.method, "POST");
assert.equal(req.url, "https://your-endpoint.com/path");
assert.equal(req.headers.length, 2);
assert.equal(req.body, '{"sessionId":42,"pageTitle":"page title"}');
});
});

});
});
7 changes: 4 additions & 3 deletions types/interfaces/edgee-protocols-data-collection.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export namespace EdgeeProtocolsDataCollection {
export function page(e: Event, cred: Dict): EdgeeRequest;
export function track(e: Event, cred: Dict): EdgeeRequest;
export function user(e: Event, cred: Dict): EdgeeRequest;
export function page(e: Event, settings: Dict): EdgeeRequest;
export function track(e: Event, settings: Dict): EdgeeRequest;
export function user(e: Event, settings: Dict): EdgeeRequest;
}
export type Dict = Array<[string, string]>;
/**
Expand Down Expand Up @@ -131,5 +131,6 @@ export interface EdgeeRequest {
method: HttpMethod,
url: string,
headers: Dict,
forwardClientHeaders: boolean,
body: string,
}
6 changes: 3 additions & 3 deletions wit/deps.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[protocols]
url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.3.0.tar.gz"
sha256 = "4d412367fff6f826280acbe95f7067e362d9299d76e60994981e7e27c74d1576"
sha512 = "65021cace5ed07990fdfb563699accb975a31cb22311739ff6189849b969b06b564a0f8f72de154fd086ba474757d3cffaef0175778e4989c467280cf1c86284"
url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.4.0.tar.gz"
sha256 = "8b5c8ea97c81d1d6cf4f227e75afb8c4dc5c0a411c3a0401fb7e4f7b745e21ba"
sha512 = "16771cd12095409e7c4857a8f5c0b4ad680959e3c35dcd7999e11131bcce05d3b1a1b829daefceabbd853ae5b7f6453e3e359ddfbdebd6e2a94db6c55780368f"
2 changes: 1 addition & 1 deletion wit/deps.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.3.0.tar.gz"
protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.4.0.tar.gz"
4 changes: 2 additions & 2 deletions wit/deps/protocols/consent-mapping.wit
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package edgee:protocols;

interface consent-mapping {
type config = list<tuple<string,string>>;
type dict = list<tuple<string,string>>;

enum consent {
pending,
granted,
denied,
}

map: func(cookie: string, config: config) -> option<consent>;
map: func(cookie: string, settings: dict) -> option<consent>;
}
7 changes: 4 additions & 3 deletions wit/deps/protocols/data-collection.wit
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ interface data-collection {
method: http-method,
url: string,
headers: dict,
forward-client-headers: bool,
body: string,
}

enum http-method { GET, PUT, POST, DELETE }

page: func(e: event, cred: dict) -> result<edgee-request, string>;
track: func(e: event, cred: dict) -> result<edgee-request, string>;
user: func(e: event, cred:dict) -> result<edgee-request, string>;
page: func(e: event, settings: dict) -> result<edgee-request, string>;
track: func(e: event, settings: dict) -> result<edgee-request, string>;
user: func(e: event, settings:dict) -> result<edgee-request, string>;
}