stentor-context 1.58.1 → 1.58.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/ContextFactory.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { AppRuntimeData, Channel, Context, CrmService, ErrorService, PIIService, Request, SMSService,
|
|
1
|
+
import { AppRuntimeData, Channel, Context, CrmService, ErrorService, PIIService, Request, SessionStore, SMSService, Storage } from "stentor-models";
|
|
2
2
|
export interface ContextFactoryServices {
|
|
3
|
-
userStorageService: UserStorageService;
|
|
4
3
|
piiService: PIIService;
|
|
5
4
|
crmService?: CrmService;
|
|
6
5
|
smsService?: SMSService;
|
|
@@ -17,7 +16,7 @@ export declare class ContextFactory {
|
|
|
17
16
|
* @param appData
|
|
18
17
|
* @returns
|
|
19
18
|
*/
|
|
20
|
-
static fromRequest(request: Request, requestBody: object, services: ContextFactoryServices, channel: Channel, appData?: AppRuntimeData): Promise<Readonly<Context>>;
|
|
19
|
+
static fromRequest(request: Request, requestBody: object, storage: Storage, session: SessionStore, services: ContextFactoryServices, channel: Channel, appData?: AppRuntimeData): Promise<Readonly<Context>>;
|
|
21
20
|
private static checkStorage;
|
|
22
21
|
private static updateProfile;
|
|
23
22
|
}
|
package/lib/ContextFactory.js
CHANGED
|
@@ -13,9 +13,7 @@ exports.ContextFactory = void 0;
|
|
|
13
13
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
14
14
|
const stentor_constants_1 = require("stentor-constants");
|
|
15
15
|
const stentor_models_1 = require("stentor-models");
|
|
16
|
-
const stentor_guards_1 = require("stentor-guards");
|
|
17
16
|
const stentor_response_1 = require("stentor-response");
|
|
18
|
-
const stentor_storage_1 = require("stentor-storage");
|
|
19
17
|
class ContextFactory {
|
|
20
18
|
/**
|
|
21
19
|
* Build context from the provided request.
|
|
@@ -27,9 +25,9 @@ class ContextFactory {
|
|
|
27
25
|
* @param appData
|
|
28
26
|
* @returns
|
|
29
27
|
*/
|
|
30
|
-
static fromRequest(request, requestBody, services, channel, appData) {
|
|
28
|
+
static fromRequest(request, requestBody, storage, session, services, channel, appData) {
|
|
31
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const {
|
|
30
|
+
const { piiService, crmService, eventService, smsService } = services;
|
|
33
31
|
const device = channel.capabilities(requestBody);
|
|
34
32
|
const response = channel.builder
|
|
35
33
|
? new channel.builder(Object.assign({ device }, appData))
|
|
@@ -37,33 +35,11 @@ class ContextFactory {
|
|
|
37
35
|
if (!request) {
|
|
38
36
|
throw new TypeError(`Request is required when building context.`);
|
|
39
37
|
}
|
|
40
|
-
if (!userStorageService) {
|
|
41
|
-
throw new TypeError(`UserStorageService is required when building context.`);
|
|
42
|
-
}
|
|
43
38
|
if (!request.userId) {
|
|
44
39
|
throw new TypeError(`User ID on the request is required when building context.`);
|
|
45
40
|
}
|
|
46
|
-
// Get the storage
|
|
47
|
-
let storage = yield userStorageService.get(request.userId);
|
|
48
|
-
// Create it if it doesn't exist.
|
|
49
41
|
if (!storage) {
|
|
50
|
-
|
|
51
|
-
createdTimestamp: Date.now(),
|
|
52
|
-
history: {
|
|
53
|
-
handler: []
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// First time users might not have history on storage yet,
|
|
58
|
-
// make sure it exists
|
|
59
|
-
if (!storage.history) {
|
|
60
|
-
storage.history = {
|
|
61
|
-
handler: []
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
else if (!Array.isArray(storage.history.handler)) {
|
|
65
|
-
// make sure it has an array of handlers
|
|
66
|
-
storage.history.handler = [];
|
|
42
|
+
throw new TypeError(`Storage is required when building context.`);
|
|
67
43
|
}
|
|
68
44
|
// Pii
|
|
69
45
|
let pii;
|
|
@@ -75,19 +51,6 @@ class ContextFactory {
|
|
|
75
51
|
console.error("Cannot fetch initial PII record");
|
|
76
52
|
}
|
|
77
53
|
}
|
|
78
|
-
// Take care of the session store. If doesn't exist or the session id doesn't match the stored one, create a new store.
|
|
79
|
-
if ((0, stentor_guards_1.hasSessionId)(request)) {
|
|
80
|
-
if (!request.sessionId) {
|
|
81
|
-
throw new Error(`Session ID is undefined when attempting to create update / retreive session store. ${request.sessionId}`);
|
|
82
|
-
}
|
|
83
|
-
if (!storage.sessionStore || storage.sessionStore.id !== request.sessionId) {
|
|
84
|
-
storage.sessionStore = {
|
|
85
|
-
id: request.sessionId,
|
|
86
|
-
data: {}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const session = (0, stentor_storage_1.createSessionStore)(storage);
|
|
91
54
|
/**
|
|
92
55
|
* This method is to request granted user profile data. We don't return it - we just say if AVAILABLE or not (or deferred)
|
|
93
56
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextFactory.js","sourceRoot":"","sources":["../src/ContextFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"ContextFactory.js","sourceRoot":"","sources":["../src/ContextFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,yDAA4D;AAC5D,mDAgBwB;AAExB,uDAAmD;AASnD,MAAa,cAAc;IACvB;;;;;;;;;OASG;IACI,MAAM,CAAO,WAAW,CAC3B,OAAgB,EAChB,WAAmB,EACnB,OAAgB,EAChB,OAAqB,EACrB,QAAgC,EAChC,OAAgB,EAChB,OAAwB;;YAExB,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;YAEtE,MAAM,MAAM,GAAW,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;YAEzD,MAAM,QAAQ,GAAqC,OAAO,CAAC,OAAO;gBAC9D,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,iBAAG,MAAM,IAAK,OAAO,EAAG;gBAC7C,CAAC,CAAC,IAAI,kC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CAAC;gBACxB,MAAM;YACV,KAAK,MAAM;gBACP,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC;gBACjB,MAAM;YACV,KAAK,wBAAwB;gBACzB,KAAK,GAAG,GAAG,CAAC,cAAc,CAAC;gBAC3B,MAAM;YACV,KAAK,yBAAyB;gBAC1B,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC;gBAC5B,MAAM;YACV,KAAK,MAAM;gBACP,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAChD;gBACI,MAAM,IAAI,KAAK,CAAC,2BAA2B,YAAY,EAAE,CAAC,CAAC;SAClE;QAED,IAAI,KAAK,EAAE;YACP,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,GAAQ,EAAE,WAAwB;QAC3D,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,WAAW,CAAC,KAAK,CAAC;QACzD,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,IAAI,WAAW,CAAC,KAAK,CAAC;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,CAAC;QACxC,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,eAAe,IAAI,WAAW,CAAC,eAAe,CAAC;QACzE,GAAG,CAAC,cAAc,GAAG,GAAG,CAAC,cAAc,IAAI,WAAW,CAAC,cAAc,CAAC;IAC1E,CAAC;CACJ;AA/JD,wCA+JC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.58.
|
|
7
|
+
"version": "1.58.3",
|
|
8
8
|
"description": "Context for stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -23,16 +23,15 @@
|
|
|
23
23
|
"mocha": "9.2.2",
|
|
24
24
|
"sinon": "15.2.0",
|
|
25
25
|
"sinon-chai": "3.7.0",
|
|
26
|
-
"stentor-models": "1.58.
|
|
26
|
+
"stentor-models": "1.58.3",
|
|
27
27
|
"ts-node": "10.9.1",
|
|
28
28
|
"typescript": "5.2.2"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@xapp/patterns": "2.0.1",
|
|
32
|
-
"stentor-constants": "1.58.
|
|
33
|
-
"stentor-
|
|
34
|
-
"stentor-
|
|
35
|
-
"stentor-storage": "1.58.1"
|
|
32
|
+
"stentor-constants": "1.58.3",
|
|
33
|
+
"stentor-response": "1.58.3",
|
|
34
|
+
"stentor-storage": "1.58.3"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
38
37
|
"stentor-models": "1.x"
|
|
@@ -42,5 +41,5 @@
|
|
|
42
41
|
"clean": "rm -rf ./lib/*",
|
|
43
42
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "fa49afa8147a5d7457d17073758c8a30c9bfbdb2"
|
|
46
45
|
}
|