Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
feat: Adds statement creators for completed sale and generated lead (…
Browse files Browse the repository at this point in the history
…LLC-36) (#10)
  • Loading branch information
lydiamross authored May 7, 2020
1 parent a13ebf7 commit b33f49c
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/examples/completedSale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import completedSale from '../statementCreators/completedSale';

const statement = completedSale({
actionDate: new Date(),
activityUrl: 'https://demo.example.org/courses/demo-course',
siteUrl: 'https://demo.example.org',
siteName: 'Demo Example Site',
platformUrl: 'https://example.org',
platformName: 'Example Platform',
userId: '123',
userIdProviderUrl: 'https://demo.example.org',
userEmail: '[email protected]',
userDisplayName: 'Demo User',
isWon: true,
closedReason: 'Too expensive',
accountDisplayName: 'Example Account',
accountUrl: 'https://demo.example.org',
});

export default statement;
16 changes: 16 additions & 0 deletions src/examples/generatedLead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import generatedLead from '../statementCreators/generatedLead';

const statement = generatedLead({
actionDate: new Date(),
activityUrl: 'https://demo.example.org/courses/demo-course',
siteUrl: 'https://demo.example.org',
siteName: 'Demo Example Site',
platformUrl: 'https://example.org',
platformName: 'Example Platform',
userId: '123',
userIdProviderUrl: 'https://demo.example.org',
userEmail: '[email protected]',
userDisplayName: 'Demo User',
});

export default statement;
10 changes: 10 additions & 0 deletions src/statementConstants/activityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export const image = 'http://activitystrea.ms/schema/1.0/image';
*/
export const issue = 'http://activitystrea.ms/schema/1.0/issue';

/**
* Represents a person or business who may eventually become a client
*/
export const salesLead = `${customBaseUrl}/sales-lead`;

/**
* Means of expressing a link to another resource within, or external to, an activity.
* Not synonymous with launching another resource.
Expand Down Expand Up @@ -172,6 +177,11 @@ export const resourceStructure = `${customBaseUrl}/resource-structure`;
*/
export const resourceStructureNode = `${customBaseUrl}/resource-structure-node`;

/**
* Represents a sales opportunity.
*/
export const salesOpportunity = 'http://id.tincanapi.com/activitytype/sales-opportunity';

/**
* Represents a feature to enable admins to manage access on a per-user or per-group basis.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/statementConstants/verbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const attended = createVerb('http://activitystrea.ms/schema/1.0/attend',
export const bookmarked = createVerb('http://id.tincanapi.com/verb/bookmarked', 'bookmarked');
export const called = createVerb('http://id.tincanapi.com/verb/called', 'called');
export const canceled = createVerb('https://w3id.org/xapi/dod-isd/verbs/canceled', 'canceled');
export const closedSale = createVerb(
'http://id.tincanapi.com/verb/closed-sale',
'closed a sale with',
);
export const commentedOn = createVerb('http://adlnet.gov/expapi/verbs/commented', 'commented on');
export const completed = createVerb('http://adlnet.gov/expapi/verbs/completed', 'completed');
export const created = createVerb('http://activitystrea.ms/schema/1.0/create', 'created');
Expand All @@ -32,6 +36,10 @@ export const evaluated = createVerb('http://www.tincanapi.co.uk/verbs/evaluated'
export const exited = createVerb('http://adlnet.gov/expapi/verbs/exited', 'exited');
export const filled = createVerb('https://w3id.org/xapi/dod-isd/verbs/filled-out', 'filled');
export const followed = createVerb('https://w3id.org/xapi/dod-isd/verbs/followed', 'followed');
export const generated = createVerb(
'https://w3id.org/xapi/dod-isd/verbs/generated',
'generated a lead with',
);
export const joined = createVerb('http://activitystrea.ms/schema/1.0/join', 'joined');
export const launched = createVerb('http://adlnet.gov/expapi/verbs/launched', 'launched');
export const liked = createVerb('https://w3id.org/xapi/acrossx/verbs/liked', 'liked');
Expand Down
82 changes: 82 additions & 0 deletions src/statementCreators/completedSale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import UserSiteAction from '../actionUtils/UserSiteAction';
import { organization, salesOpportunity, site, source } from '../statementConstants/activityTypes';
import { closedSale } from '../statementConstants/verbs';
import createActivity from '../statementUtils/createActivity';
import createAgent from '../statementUtils/createAgent';
import createTimestamp from '../statementUtils/createTimestamp';
import { Extensions, Statement } from '../statementUtils/types';

export interface CompletedSaleAction extends UserSiteAction {
/** The URL where the activity can be accessed. */
readonly activityUrl: string;

/** The human readable name for the activity. */
readonly activityName?: string;

/** Additional properties of the activity. */
readonly activityExtensions?: Extensions;

/** Determines if the sale was a success or failure. */
readonly isWon?: boolean;

/** The reason for which a sale or opportunity is closed, usually when lost */
readonly closedReason?: string;

/** The URL or identifier of the account or organization linked to the sale or opportunity. */
readonly accountUrl: string;

/** The name of the account or organization linked to the sale or opportunity. */
readonly accountDisplayName?: string;
}

/**
* Creates an xAPI Statement to represent a user completing a face-to-face meeting.
*/
export default function completedSale(action: CompletedSaleAction): Statement {
return {
timestamp: createTimestamp(action.actionDate),
actor: createAgent({
displayName: action.userDisplayName,
id: action.userId,
idProviderUrl: action.userIdProviderUrl,
email: action.userEmail,
}),
verb: closedSale,
object: createActivity({
type: salesOpportunity,
url: action.activityUrl,
name: action.activityName,
extensions: action.activityExtensions,
}),
context: {
platform: action.platformName,
language: 'en',
extensions: action.contextExtensions,
contextActivities: {
grouping: [
createActivity({
type: site,
url: action.siteUrl,
name: action.siteName,
}),
],
parent: [
createActivity({
type: organization,
url: action.accountUrl,
name: action.accountDisplayName,
}),
],
category: [createActivity({
type: source,
url: action.platformUrl,
name: action.platformName,
})],
},
},
result: {
success: action.isWon,
response: action.closedReason,
},
};
}
57 changes: 57 additions & 0 deletions src/statementCreators/generatedLead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import UserSiteAction from '../actionUtils/UserSiteAction';
import { salesLead, site, source } from '../statementConstants/activityTypes';
import { generated } from '../statementConstants/verbs';
import createActivity from '../statementUtils/createActivity';
import createAgent from '../statementUtils/createAgent';
import createTimestamp from '../statementUtils/createTimestamp';
import { Extensions, Statement } from '../statementUtils/types';

export interface GeneratedLeadAction extends UserSiteAction {
/** The URL where the activity can be accessed. */
readonly activityUrl: string;

/** The human readable name for the activity. */
readonly activityName?: string;

/** Additional properties of the activity. */
readonly activityExtensions?: Extensions;
}

/**
* Creates an xAPI Statement to represent a user completing a face-to-face meeting.
*/
export default function generatedLead(action: GeneratedLeadAction): Statement {
return {
timestamp: createTimestamp(action.actionDate),
actor: createAgent({
displayName: action.userDisplayName,
id: action.userId,
idProviderUrl: action.userIdProviderUrl,
email: action.userEmail,
}),
verb: generated,
object: createActivity({
type: salesLead,
url: action.activityUrl,
name: action.activityName,
extensions: action.activityExtensions,
}),
context: {
platform: action.platformName,
language: 'en',
extensions: action.contextExtensions,
contextActivities: {
grouping: [createActivity({
type: site,
url: action.siteUrl,
name: action.siteName,
})],
category: [createActivity({
type: source,
url: action.platformUrl,
name: action.platformName,
})],
},
},
};
}

0 comments on commit b33f49c

Please sign in to comment.