Skip to content

Commit 76c3261

Browse files
committed
Merge branch 'azure-deploy-prod' into base
2 parents 60ee198 + 84c5f4c commit 76c3261

18 files changed

+443
-84
lines changed

inc/js/api-functions.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,20 @@ async function memory(ctx){
246246
}
247247
}
248248
/**
249-
* Validates api token
249+
* Given an itemId, obscures aspects of contents of the data record.
250+
* @param {Koa} ctx - Koa Context object
251+
* @returns {Promise<object>} - Promise object representing obscured item
252+
*/
253+
async function obscure(ctx){
254+
await mAPIKeyValidation(ctx)
255+
const { itemId: iid, } = ctx.request?.body ?? {}
256+
if(!ctx.Globals.isValidGuid(iid))
257+
ctx.throw(400, 'Improper `itemId` provided in request')
258+
const { avatar, mbr_id, } = ctx.state
259+
ctx.body = await avatar.obscure(mbr_id, iid)
260+
}
261+
/**
262+
* Validates api token.
250263
* @module
251264
* @public
252265
* @param {object} ctx Koa context object
@@ -309,6 +322,7 @@ async function mAPIKeyValidation(ctx){ // transforms ctx.state
309322
if(ctx.params.mid === ':mid')
310323
ctx.params.mid = undefined
311324
const memberId = ctx.params?.mid
325+
?? ctx.request.body?.mbr_id
312326
?? ctx.request.body?.memberKey
313327
?? ctx.session?.APIMemberKey
314328
if(!memberId?.length)
@@ -350,6 +364,7 @@ export {
350364
keyValidation,
351365
logout,
352366
memory,
367+
obscure,
353368
register,
354369
tokenValidation,
355370
upload,

inc/js/core.mjs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,25 @@ class MyLife extends Organization { // form=server
259259
})
260260
return experiences
261261
}
262-
async datacore(_mbr_id){
263-
if(!_mbr_id || _mbr_id===this.mbr_id) throw new Error('datacore cannot be accessed')
264-
return await this.factory.datacore(_mbr_id)
262+
/**
263+
* Challenges and logs in member.
264+
* @param {string} memberId - Member id to challenge.
265+
* @param {string} passphrase - Passphrase response to challenge.
266+
* @returns {boolean} - Whether or not member is logged in successfully.
267+
*/
268+
async challengeAccess(memberId, passphrase){
269+
const challengeSuccessful = await this.factory.challengeAccess(memberId, passphrase)
270+
return challengeSuccessful
271+
}
272+
/**
273+
* Returns the datacore object for the specified member id.
274+
* @param {string} mbr_id - The Member id to access datacore
275+
* @returns {Promise<object>} - Datacore object for member id
276+
*/
277+
async datacore(mbr_id){
278+
if(!mbr_id || mbr_id===this.mbr_id)
279+
throw new Error('datacore cannot be accessed')
280+
return await this.factory.datacore(mbr_id)
265281
}
266282
/**
267283
* Submits and returns the journal or diary entry to MyLife via API.

inc/js/functions.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
/* module export functions */
77
async function about(ctx){
88
ctx.state.title = `About MyLife`
9-
await ctx.render('about') // about
9+
await ctx.render('about')
1010
}
1111
/**
1212
* Activate a bot for the member
@@ -85,7 +85,13 @@ async function challenge(ctx){
8585
const { mid, } = ctx.params
8686
if(!mid?.length)
8787
ctx.throw(400, `challenge request requires member id`)
88-
ctx.body = await ctx.session.MemberSession.challengeAccess(mid, passphrase)
88+
if(!ctx.state.MemberSession.locked)
89+
return true
90+
const challengeSuccessful = await ctx.MyLife.challengeAccess(mid, passphrase)
91+
const { MemberSession, } = ctx.session
92+
MemberSession.challengeOutcome = challengeSuccessful
93+
await MemberSession.init(mid)
94+
ctx.body = !MemberSession.locked
8995
}
9096
/**
9197
* Chat with the member's avatar.
@@ -242,6 +248,16 @@ async function migrateChat(ctx){
242248
const { avatar, } = ctx.state
243249
ctx.body = await avatar.migrateChat(tid)
244250
}
251+
/**
252+
* Given an itemId, obscures aspects of contents of the data record.
253+
* @param {Koa} ctx - Koa Context object
254+
* @returns {object} - The item obscured
255+
*/
256+
async function obscure(ctx){
257+
const { iid, } = ctx.params
258+
const { avatar, } = ctx.state
259+
ctx.body = await avatar.obscure(iid)
260+
}
245261
/**
246262
* Reset the passphrase for the member's avatar.
247263
* @param {Koa} ctx - Koa Context object
@@ -416,6 +432,7 @@ export {
416432
members,
417433
migrateBot,
418434
migrateChat,
435+
obscure,
419436
passphraseReset,
420437
privacyPolicy,
421438
retireBot,

inc/js/globals.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ const mAiJsFunctions = {
9696
]
9797
}
9898
},
99+
obscure: {
100+
description: "Obscures a summary so that no human names are present.",
101+
name: "obscure",
102+
parameters: {
103+
type: "object",
104+
properties: {
105+
itemId: {
106+
description: "Id of summary to obscure",
107+
format: "uuid",
108+
type: "string"
109+
}
110+
},
111+
required: [
112+
"itemId"
113+
]
114+
}
115+
},
99116
storySummary: {
100117
description: 'Generate a complete multi-paragraph STORY summary with keywords and other critical data elements.',
101118
name: 'storySummary',
@@ -177,7 +194,7 @@ const mAiJsFunctions = {
177194
},
178195
required: [
179196
"itemId",
180-
"title"
197+
"summary"
181198
]
182199
}
183200
},

inc/js/memory-functions.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ async function livingMemory(ctx){
4949
const { Globals, MyLife, } = ctx
5050
const { avatar, } = ctx.state
5151
if(!Globals.isValidGuid(iid))
52-
return ctx.throw(400, 'Invalid Item ID')
52+
ctx.throw(400, 'Invalid Item ID')
53+
ctx.throw(501, 'Not Implemented')
5354
ctx.body = await avatar.livingMemory(iid)
5455
}
5556
/* exports */
@@ -58,5 +59,4 @@ export {
5859
improveMemory,
5960
endMemory,
6061
reliveMemory,
61-
livingMemory,
6262
}

0 commit comments

Comments
 (0)