Skip to content

Commit

Permalink
Adds ZarazContext type
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenly committed Nov 16, 2024
1 parent 471e2d3 commit d10f3e8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Community toolkit package for working and building with Zaraz
This toolkit is broken down into several different tools that can be used to work with Zaraz. The tools types are as follows:
- Mocking / Testing Tools
- Managed Component Utilities
- Context Enrichment Tools *soon*
- Context Enrichment Tools
- Consent Management Tools *soon*
- Consent Management React Components Primitives *soon*

Expand Down Expand Up @@ -79,11 +79,17 @@ console.log(hash); // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e7304336293
```

## Context Enrichment Tools
> [!NOTE]
> Coming soon!
### ZarazContext
`interface ZarazContext`
```typescript
// within a context enricher:
const { system, client } = await request.json() as ZarazContext;
```

> Provides a TypeScript type for the Zaraz context object.
## Consent Management Tools
> [!NOTE]
> [!NOTE]
> Coming soon!
## Consent Management React Components
Expand Down
9 changes: 9 additions & 0 deletions src/enrichment/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, it, expect } from 'vitest';
import type { ZarazContext } from '.';

describe('enrichment', async () => {
it('should export type ZarazContext', async () => {
const contextObject = {} as ZarazContext;
expect(contextObject).toBeDefined();
});
});
64 changes: 64 additions & 0 deletions src/enrichment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Client } from '@managed-components/types';

/**
* System Object Type.
* Contains the page, cookies, device, consent, clientKV, and misc objects.
* @since 2024-08-30
* @version 0.1.0
* @author mackenly
* @see https://developers.cloudflare.com/zaraz/reference/context/
*/
interface System {
page: {
query: Object | any;
title: string;
url: URL;
referrer: string;
encoding: string;
},
cookies: Object | any;
device: {
ip: string;
resolution: string;
viewport: string;
language: string;
location: Object | any;
'user-agent': {
ua: string;
browser: {
name: string;
version: string;
};
engine: {
name: string;
version: string;
};
os: {
name: string;
version: string;
};
device: string;
cpu: string;
};
},
consent: Object | any;
clientKV: Object | any;
misc: {
random: number;
timestamp: number;
timestampMilliseconds: number;
}
}

/**
* Zaraz Context Enricher Type.
* Contains the system and client objects.
* @since 2024-08-30
* @version 0.1.0
* @author mackenly
* @see https://developers.cloudflare.com/zaraz/advanced/context-enricher/
*/
export interface ZarazContext {
system: System;
client: Client;
}

0 comments on commit d10f3e8

Please sign in to comment.