Skip to content

Consent management component #12

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

Merged
merged 4 commits into from
Apr 24, 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
28 changes: 12 additions & 16 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
name: Build and Deploy

name: Check
on:
push:
branches:
- main
pull_request:
branches:
- main

env:
EDGEE_API_TOKEN: ${{ secrets.EDGEE_API_TOKEN }}

jobs:
build:
full-ci:
name: Full CI (${{ matrix.dir }})
runs-on: ubuntu-latest

strategy:
matrix:
dir: [consent-management, data-collection]
defaults:
run:
working-directory: ${{ matrix.dir }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install edgee
uses: edgee-cloud/[email protected]

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

- name: Install edgee
uses: edgee-cloud/[email protected]

- name: Build
run: |
edgee component build

- name: Verify .wasm file exists
run: |
if [ ! -f "./example-ts-component.wasm" ]; then
echo "❌ Error: example-ts-component.wasm not found" >&2
exit 1
fi

- name: Run tests
run: npm test
9 changes: 9 additions & 0 deletions consent-management/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Node stuff
/node_modules
/coverage

.edgee/
src/index.js

# Build artifacts
*.wasm
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions consent-management/edgee-component.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
manifest-version = 1

[component]
name = "example-ts-consent-management-component"
version = "1.0.0"
category = "consent-management"
subcategory = "consent-mapping"
description = "Example TypeScript component for consent management"
documentation = "https://github.com/edgee-cloud/example-ts-component"
repository = "https://github.com/edgee-cloud/example-ts-component"
language = "TypeScript"
wit-version = "1.0.0"

[component.build]
command = "npm install && npm run generate && npm run build"
output_path = "./example-ts-component.wasm"

[component.settings.example]
title = "Example Config Field"
type = "string"
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions consent-management/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "example-ts-component",
"type": "module",
"main": "src/index.ts",
"types": "types/wit.d.ts",
"scripts": {
"generate": "npx @bytecodealliance/jco types .edgee/wit -o types",
"compile": "npx tsc",
"build": "npm run compile && npx @bytecodealliance/jco componentize src/index.js --wit .edgee/wit -o example-ts-component.wasm -n consent-management -d all",
"lint": "npx eslint",
"test": "mocha",
"coverage": "c8 --src js --all -r text -r text-summary npm test"
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"@types/chai": "^5.0.1",
"@types/mocha": "^10.0.10",
"@types/sinon": "^17.0.3",
"c8": "^10.1.3",
"chai": "^5.1.2",
"eslint": "^9.20.0",
"mocha": "^11.1.0",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"typescript": "^5.7.3",
"typescript-eslint": "^8.24.0"
}
}
32 changes: 32 additions & 0 deletions consent-management/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type {
consentManagement as EdgeeConsentManagement,
} from "../types/wit";


const convertDict = (dict: EdgeeConsentManagement.Dict): Map<string, string> => {
const data = new Map<string, string>();

for (const [key, value] of dict) {
data.set(key, value);
}

return data;
};

export const consentManagement: typeof EdgeeConsentManagement = {
map(cookies: EdgeeConsentManagement.Dict, settings: EdgeeConsentManagement.Dict) {
const dictSettings = convertDict(settings);
const dictCookies = convertDict(cookies);

if (!dictCookies.has('example')) {
return;
}
const example = dictCookies.get('example');
if (example === "granted") {
return "granted";
} else if (example === "denied") {
return "denied";
}
return "pending";
},
};
23 changes: 23 additions & 0 deletions consent-management/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { assert } from "chai";
import { describe, it } from "mocha";
import { consentManagement } from '../src/index';
import { Dict } from "../types/interfaces/edgee-components-consent-management";

describe('consent management component', function () {

const sampleSettings: Dict = [
["example", "api_value"]
];

const sampleCookies: Dict = [
["example", "denied"]
];

describe('#map()', function () {
it('should return consent denied', function () {
const req = consentManagement.map(sampleCookies, sampleSettings);
assert.equal(req, "denied");
});
});

});
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @module Interface edgee:components/[email protected] **/
export function map(cookies: Dict, settings: Dict): Consent | undefined;
export type Dict = Array<[string, string]>;
/**
* # Variants
*
* ## `"pending"`
*
* ## `"granted"`
*
* ## `"denied"`
*/
export type Consent = 'pending' | 'granted' | 'denied';
2 changes: 2 additions & 0 deletions consent-management/types/wit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// world edgee:native/consent-management
export * as consentManagement from './interfaces/edgee-components-consent-management.js'; // export edgee:components/[email protected]
9 changes: 9 additions & 0 deletions data-collection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Node stuff
/node_modules
/coverage

.edgee/
src/index.js

# Build artifacts
*.wasm
Loading