Skip to content

Commit

Permalink
Fix types relating to invite creation (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal authored Sep 12, 2024
1 parent 15bd602 commit 56c6719
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envoy/envoy-integrations-sdk",
"version": "2.2.0",
"version": "2.2.1",
"description": "SDK for building Envoy integrations.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
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';

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
};
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;
};
}
};
}

0 comments on commit 56c6719

Please sign in to comment.