Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: envoy/envoy-integrations-sdk-nodejs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.0.1
Choose a base ref
...
head repository: envoy/envoy-integrations-sdk-nodejs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: typescript
Choose a head ref
  • 9 commits
  • 12 files changed
  • 4 contributors

Commits on Aug 21, 2024

  1. fix: bump jsonwebtoken to address vulnerability (#57)

    * fix: bump jsonwebtoken to address vulnerability
    
    * fix: bump patch version
    ahmed-envoy authored Aug 21, 2024
    Copy the full SHA
    591936e View commit details

Commits on Aug 29, 2024

  1. Add EnvoyMetaZone (#58)

    brianswko authored Aug 29, 2024
    Copy the full SHA
    6b18dae View commit details
  2. Bump to 2.1.0 (#59)

    brianswko authored Aug 29, 2024
    Copy the full SHA
    963524b View commit details

Commits on Sep 9, 2024

  1. Filter flows by enabled attribute (#60)

    kamal authored Sep 9, 2024
    Copy the full SHA
    ae766ce View commit details
  2. Add missing chalk dependency (#61)

    kamal authored Sep 9, 2024
    Copy the full SHA
    fdbfef7 View commit details
  3. 2.2.0 (#62)

    kamal authored Sep 9, 2024
    Copy the full SHA
    15bd602 View commit details

Commits on Sep 12, 2024

  1. Fix types relating to invite creation (#63)

    kamal authored Sep 12, 2024
    Copy the full SHA
    56c6719 View commit details
  2. 2.2.1 (#64)

    * back one
    
    * 2.2.1
    kamal authored Sep 12, 2024
    Copy the full SHA
    c352580 View commit details

Commits on Nov 21, 2024

  1. feat: Adding createReservations function to the EnvoyUserAPI (#66)

    ArvindEnvoy authored Nov 21, 2024
    Copy the full SHA
    f0f3f60 View commit details
19 changes: 19 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -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` |
1,754 changes: 1,592 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envoy/envoy-integrations-sdk",
"version": "2.0.1",
"version": "2.2.3",
"description": "SDK for building Envoy integrations.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -33,16 +33,17 @@
"dependencies": {
"@types/dotenv": "^8.2.0",
"@types/faker": "^5.5.6",
"@types/jsonwebtoken": "^8.5.1",
"@types/jsonwebtoken": "^9.0.0",
"@types/node": "^15.12.0",
"@types/qs": "^6.9.6",
"axios": "^1.4.0",
"body-parser": "^1.19.0",
"chalk": "^4.1.2",
"dataloader": "^2.0.0",
"dotenv-flow": "^3.2.0",
"factory.ts": "^0.5.2",
"faker": "^5.5.3",
"jsonwebtoken": "^8.5.1",
"jsonwebtoken": "^9.0.0",
"lodash.ismatch": "^4.4.0",
"luxon": "^1.27.0",
"qs": "^6.10.1"
3 changes: 3 additions & 0 deletions src/factories/eventBodyFactory.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { eventMetaFactory } from './metaFactory';
export const eventBodyFactoryDefaultIds = {
locationId: '1',
companyId: '1',
zoneId: '1',
};

export type EventBodyFactoryOptions<Event, Config, Payload> = {
@@ -13,6 +14,7 @@ export type EventBodyFactoryOptions<Event, Config, Payload> = {
scope: Array<EnvoyUserAPIScope>,
locationId?: string,
companyId?: string,
zoneId?: string,
};

export default function eventBodyFactory<
@@ -29,6 +31,7 @@ export default function eventBodyFactory<
options.scope,
options.locationId || eventBodyFactoryDefaultIds.locationId,
options.companyId || eventBodyFactoryDefaultIds.companyId,
options.zoneId || eventBodyFactoryDefaultIds.zoneId,
).build(),
payload: options.payload,
};
19 changes: 19 additions & 0 deletions src/factories/metaFactory.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import {
EnvoyMetaCompany,
EnvoyMetaJob,
EnvoyMetaLocation,
EnvoyMetaZone,
EnvoyRouteMeta,
} from '../sdk/EnvoyMeta';
import { EnvoyUserAPIScope } from '../sdk/EnvoyUserAPI';
@@ -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',
@@ -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,
@@ -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,
3 changes: 3 additions & 0 deletions src/factories/routeBodyFactory.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { routeMetaFactory } from './metaFactory';
export const routeBodyFactoryDefaultIds = {
locationId: '1',
companyId: '1',
zoneId: '1',
};

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

@@ -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,
};
1 change: 1 addition & 0 deletions src/resources/FlowResource.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ export type FlowSortFields = 'name' | 'created_at' | '-name' | '-created_at';
*/
export interface FlowFilterFields {
'employee-centric'?: boolean;
enabled?: boolean;
location?: string;
}

43 changes: 35 additions & 8 deletions src/resources/InviteResource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import JSONAPIData from '../util/json-api/JSONAPIData';
import JSONAPIModel from '../util/json-api/JSONAPIModel';

/**
@@ -32,15 +33,15 @@ export interface InviteAttributes {
auto_approved: boolean;
report: Array<{
reason: string;
result: 'pass' | 'fail' | 'pending',
source: string,
result: 'pass' | 'fail' | 'pending';
source: string;
messages: {
failure?: {
text: string,
header: string,
}
}
}>
text: string;
header: string;
};
};
}>;
};
email?: string;
'expected-arrival-time'?: string;
@@ -89,4 +90,30 @@ export type InviteModel = JSONAPIModel<InviteAttributes, InviteRelationships, 'i
/**
* @category API Resource
*/
export type InviteCreationModel = JSONAPIModel<InviteCreationAttributes, InviteRelationships, 'invites', undefined>;
type InviteCreationRequiredRelationships = 'location'; // surprising, but flow is not required. if not provided, it will be defaulted
type InviteCreationProhibitedRelationships = 'creator';
type InviteCreationOptionalRelationships = Exclude<
InviteRelationships,
InviteCreationRequiredRelationships | InviteCreationProhibitedRelationships
>;

/**
* Here we are going to do a little surgery on JSONAPIModel to allow us to specify required and optional relationships.
* We do this by first omitting the relationships field from JSONAPIModel, then adding it back in with modified type.
*/
export type InviteCreationModel = Omit<
JSONAPIModel<InviteCreationAttributes, InviteRelationships, 'invites', undefined>,
'relationships'
> & {
relationships: {
[key in InviteCreationRequiredRelationships]: {
data: JSONAPIData | Array<JSONAPIData>;
};
} & {
[key in InviteCreationOptionalRelationships]?: {
data: JSONAPIData | Array<JSONAPIData> | null;
};
} & {
[key in InviteCreationProhibitedRelationships]?: never;
};
};
40 changes: 40 additions & 0 deletions src/resources/ReservationResource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import JSONAPIModel from "../util/json-api/JSONAPIModel";

export interface ReservationAttributes {
'is-partial-day': boolean;
'updated-at': number;
'is-assignable': boolean;
'name': string;
'assigned-to': string | null;
'neighborhood-id': number;
'created-at': number;
'neighborhood': number | null;
'parent-desk-id': string | null;
'availability': string | null;
'enabled': boolean;
'x-pos': number | null;
'y-pos': number | null;
}

export interface ReservationCreationAttributes {
// Required fields
userId: number;

// Optional fields
deskId?: number | null;
locationId?: number | null;
inviteId?: number | null;
entryId?: number | null;
startTime?: number | null; // Unix timestamp
endTime?: number | null; // Unix timestamp

meta?: {
autoAssignDesk?: boolean;
};
}

export type ReservationRelationships = 'location' | 'desk' | 'company' | 'floor' | 'employee' | 'entry' | 'invite' | 'user';

export type ReservationModel = JSONAPIModel<ReservationAttributes, ReservationRelationships, 'reservations'>


16 changes: 16 additions & 0 deletions src/sdk/EnvoyMeta.ts
Original file line number Diff line number Diff line change
@@ -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`.
@@ -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,
};

@@ -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,
};
42 changes: 40 additions & 2 deletions src/sdk/EnvoyUserAPI.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import { UserModel } from '../resources/UserResource';
import { envoyBaseURL, envoyClientId, envoyClientSecret } from '../constants';
import { EnvoyMetaAuth } from './EnvoyMeta';
import { sanitizeAxiosError } from '../util/axiosConstructor';
import { ReservationCreationAttributes, ReservationModel } from "../resources/ReservationResource";

export type EnvoyUserAPIScope =
'flows.read' |
@@ -195,6 +196,43 @@ export default class EnvoyUserAPI extends EnvoyAPI {
return data.data;
}

async createReservation(reservationDetails: ReservationCreationAttributes): Promise<ReservationModel> {
let createReservationBody = {
data: {
relationships: {
user: {
data: {
type: 'users',
id: reservationDetails.userId
}},
...(reservationDetails.locationId && {
location: {
data: {
type: 'locations',
id: reservationDetails.locationId
}
}
}
)
},
attributes: {
'start-time': reservationDetails.startTime,
...(reservationDetails.endTime && {
'end-time': reservationDetails.endTime
}),
'booking-source': 'EXTERNAL_API',
'booking-type': 'visitor'
}
}
}
const { data } = await this.axios({
method: 'POST',
url: '/a/rms/reservations',
data: createReservationBody,
});
return data.data;
}

/**
* Requires `invites.write` scope.
*/
@@ -305,7 +343,7 @@ export default class EnvoyUserAPI extends EnvoyAPI {
});
return data;
} catch (error) {
throw sanitizeAxiosError(error);
throw sanitizeAxiosError(error);
}
}

@@ -333,7 +371,7 @@ export default class EnvoyUserAPI extends EnvoyAPI {
});
return data;
} catch (error) {
throw sanitizeAxiosError(error);
throw sanitizeAxiosError(error);
}
}
}
7 changes: 4 additions & 3 deletions src/util/json-api/JSONAPIModel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import JSONAPIData from './JSONAPIData';

export default interface JSONAPIModel<Attributes, Relationships extends string, Type = string, ID = string> extends JSONAPIData<Type, ID> {
export default interface JSONAPIModel<Attributes, Relationships extends string, Type = string, ID = string>
extends JSONAPIData<Type, ID> {
attributes: Attributes;
relationships: {
[key in Relationships]: {
data: JSONAPIData & Array<JSONAPIData>
data: JSONAPIData | Array<JSONAPIData> | null;
};
}
};
}