Skip to content

Commit

Permalink
Add EnvoyMetaZone
Browse files Browse the repository at this point in the history
  • Loading branch information
brianswko committed Aug 29, 2024
1 parent 591936e commit a5423f2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
- [EnvoyMetaCompany](README.md#envoymetacompany)
- [EnvoyMetaJob](README.md#envoymetajob)
- [EnvoyMetaLocation](README.md#envoymetalocation)
- [EnvoyMetaZone](README.md#envoymetazone)
- [EnvoyRouteMeta](README.md#envoyroutemeta)

### Request Type aliases
Expand Down Expand Up @@ -910,6 +911,7 @@ Metadata that will be included in the request body for events.
| `install_id` | `string` |
| `job` | [EnvoyMetaJob](README.md#envoymetajob)<Event\> |
| `location` | [EnvoyMetaLocation](README.md#envoymetalocation) |
| `zone` | [EnvoyMetaZone](README.md#envoymetazone) |
| `plugin_id` | `string` |

#### Defined in
Expand Down Expand Up @@ -1016,6 +1018,22 @@ ___

[sdk/EnvoyMeta.ts:13](https://github.com/envoy/envoy-integrations-sdk-nodejs/blob/410ee70/src/sdk/EnvoyMeta.ts#L13)

### EnvoyMetaZone

Ƭ **EnvoyMetaZone**: `Object`

#### Type declaration

| Name | Type |
| :------ | :------ |
| `attributes` | `Object` |
| `attributes.address` | `string` \| ``null`` |
| `attributes.logo-url` | `string` \| ``null`` |
| `attributes.name` | `string` |
| `attributes.time-zone` | `string` |
| `id` | `string` |
| `type` | ``"zones"`` |

___

### EnvoyRouteMeta
Expand All @@ -1042,6 +1060,7 @@ like validation URLs or options URLs.
| `forwarded_bearer_token?` | `string` |
| `install_id` | `string` |
| `location` | [EnvoyMetaLocation](README.md#envoymetalocation) |
| `zone` | [EnvoyMetaZone](README.md#envoymetazone) |
| `params` | `Params` |
| `plugin_id` | `string` |
| `route` | `string` |
Expand Down
2 changes: 2 additions & 0 deletions src/factories/eventBodyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type EventBodyFactoryOptions<Event, Config, Payload> = {
scope: Array<EnvoyUserAPIScope>,
locationId?: string,
companyId?: string,
zoneId?: string,
};

export default function eventBodyFactory<
Expand All @@ -29,6 +30,7 @@ export default function eventBodyFactory<
options.scope,
options.locationId || eventBodyFactoryDefaultIds.locationId,
options.companyId || eventBodyFactoryDefaultIds.companyId,
options.zoneId || eventBodyFactoryDefaultIds.zoneId,

Check failure on line 33 in src/factories/eventBodyFactory.ts

View workflow job for this annotation

GitHub Actions / build

Property 'zoneId' does not exist on type '{ locationId: string; companyId: string; }'.
).build(),
payload: options.payload,
};
Expand Down
19 changes: 19 additions & 0 deletions src/factories/metaFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
EnvoyMetaCompany,
EnvoyMetaJob,
EnvoyMetaLocation,
EnvoyMetaZone,
EnvoyRouteMeta,
} from '../sdk/EnvoyMeta';
import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
Expand Down Expand Up @@ -55,6 +56,20 @@ export function companyFactory(id: string): Sync.Factory<EnvoyMetaCompany> {
});
}

export function zoneFactory(id: string): Sync.Factory<EnvoyMetaZone> {
const street = faker.address.streetAddress();
return Sync.makeFactory<EnvoyMetaZone>({
id,
type: 'zones',
attributes: {
address: street,
'logo-url': null,
name: faker.company.companyName(),
'time-zone': faker.address.timeZone(),
},
});
}

export function authFactory(): Sync.Factory<EnvoyMetaAuth> {
return Sync.makeFactory<EnvoyMetaAuth>({
token_type: 'Bearer',
Expand All @@ -75,12 +90,14 @@ export function routeMetaFactory<
scope: Array<EnvoyUserAPIScope>,
locationId: string,
companyId: string,
zoneId: string,
): Sync.Factory<EnvoyRouteMeta> {
return Sync.makeFactory<EnvoyRouteMeta>({
plugin_id: faker.datatype.uuid(),
install_id: Math.ceil(Math.abs(faker.datatype.number())).toString(),
location: locationFactory(locationId).build(),
company: companyFactory(companyId).build(),
zone: zoneFactory(zoneId).build(),
auth: scope.length ? authFactory().build() : null,
forwarded_bearer_token: faker.random.alphaNumeric(),
route,
Expand All @@ -95,13 +112,15 @@ export function eventMetaFactory<Config extends Record<string, unknown> = Record
scope: Array<EnvoyUserAPIScope>,
locationId: string,
companyId: string,
zoneId: string,
): Sync.Factory<EnvoyEventMeta> {
return Sync.makeFactory<EnvoyEventMeta>({
plugin_id: faker.datatype.uuid(),
install_id: Math.ceil(Math.abs(faker.datatype.number())).toString(),
job: jobFactory(event).build(),
location: locationFactory(locationId).build(),
company: companyFactory(companyId).build(),
zone: zoneFactory(zoneId).build(),
auth: scope.length ? authFactory().build() : null,
event,
config,
Expand Down
3 changes: 3 additions & 0 deletions src/factories/routeBodyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { routeMetaFactory } from './metaFactory';
export const routeBodyFactoryDefaultIds = {
locationId: '1',
companyId: '1',
zoneId: '1',
};

export type RouteBodyFactoryOptions<Config, Params, Payload> = {
Expand All @@ -13,6 +14,7 @@ export type RouteBodyFactoryOptions<Config, Params, Payload> = {
scope?: Array<EnvoyUserAPIScope>,
locationId?: string,
companyId?: string,
zoneId?: string,
route?: string,
};

Expand All @@ -31,6 +33,7 @@ export default function routeBodyFactory<
options.scope || [],
options.locationId || routeBodyFactoryDefaultIds.locationId,
options.companyId || routeBodyFactoryDefaultIds.companyId,
options.zoneId || routeBodyFactoryDefaultIds.zoneId,
).build(),
payload: options.payload,
};
Expand Down
16 changes: 16 additions & 0 deletions src/sdk/EnvoyMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ export type EnvoyMetaCompany = {
}
};

/**
* @category Meta
*/
export type EnvoyMetaZone = {
id: string,
type: 'zones',
attributes: {
address: string | null,
'logo-url': string | null,
name: string,
'time-zone': string,
}
};

/**
* A short-lived `userAPI` token.
* Will be used to construct the `userAPI` property found in `req.envoy.userAPI`.
Expand Down Expand Up @@ -71,6 +85,7 @@ export type EnvoyEventMeta<Event extends string = string, Config = Record<string
job: EnvoyMetaJob<Event>,
location: EnvoyMetaLocation,
company: EnvoyMetaCompany,
zone: EnvoyMetaZone,
auth: EnvoyMetaAuth | null,
};

Expand All @@ -88,6 +103,7 @@ export type EnvoyRouteMeta<Config = Record<string, unknown>, Params = Record<str
params: Params,
location: EnvoyMetaLocation,
company: EnvoyMetaCompany,
zone: EnvoyMetaZone,
auth: EnvoyMetaAuth | null,
forwarded_bearer_token?: string,
};
Expand Down

0 comments on commit a5423f2

Please sign in to comment.