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

Commit b33f49c

Browse files
authored
feat: Adds statement creators for completed sale and generated lead (LLC-36) (#10)
1 parent a13ebf7 commit b33f49c

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-0
lines changed

src/examples/completedSale.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import completedSale from '../statementCreators/completedSale';
2+
3+
const statement = completedSale({
4+
actionDate: new Date(),
5+
activityUrl: 'https://demo.example.org/courses/demo-course',
6+
siteUrl: 'https://demo.example.org',
7+
siteName: 'Demo Example Site',
8+
platformUrl: 'https://example.org',
9+
platformName: 'Example Platform',
10+
userId: '123',
11+
userIdProviderUrl: 'https://demo.example.org',
12+
userEmail: 'demo@example.org',
13+
userDisplayName: 'Demo User',
14+
isWon: true,
15+
closedReason: 'Too expensive',
16+
accountDisplayName: 'Example Account',
17+
accountUrl: 'https://demo.example.org',
18+
});
19+
20+
export default statement;

src/examples/generatedLead.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import generatedLead from '../statementCreators/generatedLead';
2+
3+
const statement = generatedLead({
4+
actionDate: new Date(),
5+
activityUrl: 'https://demo.example.org/courses/demo-course',
6+
siteUrl: 'https://demo.example.org',
7+
siteName: 'Demo Example Site',
8+
platformUrl: 'https://example.org',
9+
platformName: 'Example Platform',
10+
userId: '123',
11+
userIdProviderUrl: 'https://demo.example.org',
12+
userEmail: 'demo@example.org',
13+
userDisplayName: 'Demo User',
14+
});
15+
16+
export default statement;

src/statementConstants/activityTypes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export const image = 'http://activitystrea.ms/schema/1.0/image';
8989
*/
9090
export const issue = 'http://activitystrea.ms/schema/1.0/issue';
9191

92+
/**
93+
* Represents a person or business who may eventually become a client
94+
*/
95+
export const salesLead = `${customBaseUrl}/sales-lead`;
96+
9297
/**
9398
* Means of expressing a link to another resource within, or external to, an activity.
9499
* Not synonymous with launching another resource.
@@ -172,6 +177,11 @@ export const resourceStructure = `${customBaseUrl}/resource-structure`;
172177
*/
173178
export const resourceStructureNode = `${customBaseUrl}/resource-structure-node`;
174179

180+
/**
181+
* Represents a sales opportunity.
182+
*/
183+
export const salesOpportunity = 'http://id.tincanapi.com/activitytype/sales-opportunity';
184+
175185
/**
176186
* Represents a feature to enable admins to manage access on a per-user or per-group basis.
177187
*/

src/statementConstants/verbs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const attended = createVerb('http://activitystrea.ms/schema/1.0/attend',
2121
export const bookmarked = createVerb('http://id.tincanapi.com/verb/bookmarked', 'bookmarked');
2222
export const called = createVerb('http://id.tincanapi.com/verb/called', 'called');
2323
export const canceled = createVerb('https://w3id.org/xapi/dod-isd/verbs/canceled', 'canceled');
24+
export const closedSale = createVerb(
25+
'http://id.tincanapi.com/verb/closed-sale',
26+
'closed a sale with',
27+
);
2428
export const commentedOn = createVerb('http://adlnet.gov/expapi/verbs/commented', 'commented on');
2529
export const completed = createVerb('http://adlnet.gov/expapi/verbs/completed', 'completed');
2630
export const created = createVerb('http://activitystrea.ms/schema/1.0/create', 'created');
@@ -32,6 +36,10 @@ export const evaluated = createVerb('http://www.tincanapi.co.uk/verbs/evaluated'
3236
export const exited = createVerb('http://adlnet.gov/expapi/verbs/exited', 'exited');
3337
export const filled = createVerb('https://w3id.org/xapi/dod-isd/verbs/filled-out', 'filled');
3438
export const followed = createVerb('https://w3id.org/xapi/dod-isd/verbs/followed', 'followed');
39+
export const generated = createVerb(
40+
'https://w3id.org/xapi/dod-isd/verbs/generated',
41+
'generated a lead with',
42+
);
3543
export const joined = createVerb('http://activitystrea.ms/schema/1.0/join', 'joined');
3644
export const launched = createVerb('http://adlnet.gov/expapi/verbs/launched', 'launched');
3745
export const liked = createVerb('https://w3id.org/xapi/acrossx/verbs/liked', 'liked');
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import UserSiteAction from '../actionUtils/UserSiteAction';
2+
import { organization, salesOpportunity, site, source } from '../statementConstants/activityTypes';
3+
import { closedSale } from '../statementConstants/verbs';
4+
import createActivity from '../statementUtils/createActivity';
5+
import createAgent from '../statementUtils/createAgent';
6+
import createTimestamp from '../statementUtils/createTimestamp';
7+
import { Extensions, Statement } from '../statementUtils/types';
8+
9+
export interface CompletedSaleAction extends UserSiteAction {
10+
/** The URL where the activity can be accessed. */
11+
readonly activityUrl: string;
12+
13+
/** The human readable name for the activity. */
14+
readonly activityName?: string;
15+
16+
/** Additional properties of the activity. */
17+
readonly activityExtensions?: Extensions;
18+
19+
/** Determines if the sale was a success or failure. */
20+
readonly isWon?: boolean;
21+
22+
/** The reason for which a sale or opportunity is closed, usually when lost */
23+
readonly closedReason?: string;
24+
25+
/** The URL or identifier of the account or organization linked to the sale or opportunity. */
26+
readonly accountUrl: string;
27+
28+
/** The name of the account or organization linked to the sale or opportunity. */
29+
readonly accountDisplayName?: string;
30+
}
31+
32+
/**
33+
* Creates an xAPI Statement to represent a user completing a face-to-face meeting.
34+
*/
35+
export default function completedSale(action: CompletedSaleAction): Statement {
36+
return {
37+
timestamp: createTimestamp(action.actionDate),
38+
actor: createAgent({
39+
displayName: action.userDisplayName,
40+
id: action.userId,
41+
idProviderUrl: action.userIdProviderUrl,
42+
email: action.userEmail,
43+
}),
44+
verb: closedSale,
45+
object: createActivity({
46+
type: salesOpportunity,
47+
url: action.activityUrl,
48+
name: action.activityName,
49+
extensions: action.activityExtensions,
50+
}),
51+
context: {
52+
platform: action.platformName,
53+
language: 'en',
54+
extensions: action.contextExtensions,
55+
contextActivities: {
56+
grouping: [
57+
createActivity({
58+
type: site,
59+
url: action.siteUrl,
60+
name: action.siteName,
61+
}),
62+
],
63+
parent: [
64+
createActivity({
65+
type: organization,
66+
url: action.accountUrl,
67+
name: action.accountDisplayName,
68+
}),
69+
],
70+
category: [createActivity({
71+
type: source,
72+
url: action.platformUrl,
73+
name: action.platformName,
74+
})],
75+
},
76+
},
77+
result: {
78+
success: action.isWon,
79+
response: action.closedReason,
80+
},
81+
};
82+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import UserSiteAction from '../actionUtils/UserSiteAction';
2+
import { salesLead, site, source } from '../statementConstants/activityTypes';
3+
import { generated } from '../statementConstants/verbs';
4+
import createActivity from '../statementUtils/createActivity';
5+
import createAgent from '../statementUtils/createAgent';
6+
import createTimestamp from '../statementUtils/createTimestamp';
7+
import { Extensions, Statement } from '../statementUtils/types';
8+
9+
export interface GeneratedLeadAction extends UserSiteAction {
10+
/** The URL where the activity can be accessed. */
11+
readonly activityUrl: string;
12+
13+
/** The human readable name for the activity. */
14+
readonly activityName?: string;
15+
16+
/** Additional properties of the activity. */
17+
readonly activityExtensions?: Extensions;
18+
}
19+
20+
/**
21+
* Creates an xAPI Statement to represent a user completing a face-to-face meeting.
22+
*/
23+
export default function generatedLead(action: GeneratedLeadAction): Statement {
24+
return {
25+
timestamp: createTimestamp(action.actionDate),
26+
actor: createAgent({
27+
displayName: action.userDisplayName,
28+
id: action.userId,
29+
idProviderUrl: action.userIdProviderUrl,
30+
email: action.userEmail,
31+
}),
32+
verb: generated,
33+
object: createActivity({
34+
type: salesLead,
35+
url: action.activityUrl,
36+
name: action.activityName,
37+
extensions: action.activityExtensions,
38+
}),
39+
context: {
40+
platform: action.platformName,
41+
language: 'en',
42+
extensions: action.contextExtensions,
43+
contextActivities: {
44+
grouping: [createActivity({
45+
type: site,
46+
url: action.siteUrl,
47+
name: action.siteName,
48+
})],
49+
category: [createActivity({
50+
type: source,
51+
url: action.platformUrl,
52+
name: action.platformName,
53+
})],
54+
},
55+
},
56+
};
57+
}

0 commit comments

Comments
 (0)