Skip to content

Commit

Permalink
Make base64 encoding an optional parameter in Node newTracker call (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Oct 25, 2024
1 parent a95cc35 commit 6aeb241
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The Self Describing JSON which describes the event
<b>Signature:</b>

```typescript
event: SelfDescribingJson;
event: SelfDescribingJson<T>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ A Self Describing Event A custom event type, allowing for an event to be tracked
<b>Signature:</b>

```typescript
interface SelfDescribingEvent
interface SelfDescribingEvent<T = Record<string, unknown>>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [event](./browser-tracker.selfdescribingevent.event.md) | SelfDescribingJson | The Self Describing JSON which describes the event |
| [event](./browser-tracker.selfdescribingevent.event.md) | SelfDescribingJson&lt;T&gt; | The Self Describing JSON which describes the event |

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Export interface for any Self-Describing JSON such as context or Self Describing
<b>Signature:</b>

```typescript
type SelfDescribingJson<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
type SelfDescribingJson<T = Record<string, unknown>> = {
schema: string;
data: T;
data: T extends any[] ? never : T extends {} ? T : never;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Track a self-describing event happening on this page. A custom event type, allow
<b>Signature:</b>

```typescript
declare function trackSelfDescribingEvent(event: SelfDescribingEvent & CommonEventProperties, trackers?: Array<string>): void;
declare function trackSelfDescribingEvent<T = Record<string, unknown>>(event: SelfDescribingEvent<T> & CommonEventProperties, trackers?: Array<string>): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| event | SelfDescribingEvent &amp; CommonEventProperties | The event information |
| event | SelfDescribingEvent&lt;T&gt; &amp; CommonEventProperties | The event information |
| trackers | Array&lt;string&gt; | The tracker identifiers which the event will be sent to |

<b>Returns:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Build a self-describing event A custom event type, allowing for an event to be t
<b>Signature:</b>

```typescript
declare function buildSelfDescribingEvent(event: SelfDescribingEvent): PayloadBuilder;
declare function buildSelfDescribingEvent<T = Record<string, unknown>>(event: SelfDescribingEvent<T>): PayloadBuilder;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| event | SelfDescribingEvent | Contains the properties and schema location for the event |
| event | SelfDescribingEvent&lt;T&gt; | Contains the properties and schema location for the event |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The Self Describing JSON which describes the event
<b>Signature:</b>

```typescript
event: SelfDescribingJson;
event: SelfDescribingJson<T>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ A Self Describing Event A custom event type, allowing for an event to be tracked
<b>Signature:</b>

```typescript
interface SelfDescribingEvent
interface SelfDescribingEvent<T = Record<string, unknown>>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [event](./node-tracker.selfdescribingevent.event.md) | SelfDescribingJson | The Self Describing JSON which describes the event |
| [event](./node-tracker.selfdescribingevent.event.md) | SelfDescribingJson&lt;T&gt; | The Self Describing JSON which describes the event |

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Export interface for any Self-Describing JSON such as context or Self Describing
<b>Signature:</b>

```typescript
type SelfDescribingJson<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
type SelfDescribingJson<T = Record<string, unknown>> = {
schema: string;
data: T;
data: T extends any[] ? never : T extends {} ? T : never;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

## TrackerConfiguration.encodeBase64 property

Whether unstructured events and custom contexts should be base64 encoded.

<b>Signature:</b>

```typescript
encodeBase64: boolean;
encodeBase64?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ interface TrackerConfiguration
| Property | Type | Description |
| --- | --- | --- |
| [appId](./node-tracker.trackerconfiguration.appid.md) | string | |
| [encodeBase64](./node-tracker.trackerconfiguration.encodebase64.md) | boolean | |
| [encodeBase64?](./node-tracker.trackerconfiguration.encodebase64.md) | boolean | <i>(Optional)</i> Whether unstructured events and custom contexts should be base64 encoded. |
| [namespace](./node-tracker.trackerconfiguration.namespace.md) | string | |

3 changes: 1 addition & 2 deletions api-docs/docs/node-tracker/node-tracker.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ export interface TrackerConfiguration {
// (undocumented)
appId: string;
/* The application ID */
// (undocumented)
encodeBase64: boolean;
encodeBase64?: boolean;
/* The application ID */
// (undocumented)
namespace: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/node-tracker",
"comment": "Make base64 encoding an optional parameter in Node newTracker call",
"type": "none"
}
],
"packageName": "@snowplow/node-tracker"
}
7 changes: 5 additions & 2 deletions trackers/node-tracker/src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ export interface TrackerConfiguration {
namespace: string;
/* The application ID */
appId: string;
/* Whether unstructured events and custom contexts should be base64 encoded. */
encodeBase64: boolean;
/**
* Whether unstructured events and custom contexts should be base64 encoded.
* @defaultValue true
**/
encodeBase64?: boolean;
}

export type CustomEmitter = {
Expand Down
6 changes: 6 additions & 0 deletions trackers/node-tracker/test/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ function checkPayload(payloadDict: Payload, expected: Payload, t: ExecutionConte

const customFetch = () => Promise.resolve(new Response(null, { status: 200 }));

test('newTracker called with default values', (t) => {
const tracker = newTracker({ namespace: 'cf', appId: 'cfe35' }, { endpoint });
t.truthy(tracker);
t.true(tracker.getBase64Encoding());
});

for (const eventMethod of testMethods) {
test(eventMethod + ' method: track API should return eid in the payload', (t) => {
const track = newTracker(
Expand Down

0 comments on commit 6aeb241

Please sign in to comment.