Skip to content

Commit

Permalink
Merge branch 'azure-deploy-prod' into base
Browse files Browse the repository at this point in the history
  • Loading branch information
Mookse committed Oct 1, 2024
2 parents 60ee198 + 84c5f4c commit 76c3261
Show file tree
Hide file tree
Showing 18 changed files with 443 additions and 84 deletions.
17 changes: 16 additions & 1 deletion inc/js/api-functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,20 @@ async function memory(ctx){
}
}
/**
* Validates api token
* Given an itemId, obscures aspects of contents of the data record.
* @param {Koa} ctx - Koa Context object
* @returns {Promise<object>} - Promise object representing obscured item
*/
async function obscure(ctx){
await mAPIKeyValidation(ctx)
const { itemId: iid, } = ctx.request?.body ?? {}
if(!ctx.Globals.isValidGuid(iid))
ctx.throw(400, 'Improper `itemId` provided in request')
const { avatar, mbr_id, } = ctx.state
ctx.body = await avatar.obscure(mbr_id, iid)
}
/**
* Validates api token.
* @module
* @public
* @param {object} ctx Koa context object
Expand Down Expand Up @@ -309,6 +322,7 @@ async function mAPIKeyValidation(ctx){ // transforms ctx.state
if(ctx.params.mid === ':mid')
ctx.params.mid = undefined
const memberId = ctx.params?.mid
?? ctx.request.body?.mbr_id
?? ctx.request.body?.memberKey
?? ctx.session?.APIMemberKey
if(!memberId?.length)
Expand Down Expand Up @@ -350,6 +364,7 @@ export {
keyValidation,
logout,
memory,
obscure,
register,
tokenValidation,
upload,
Expand Down
22 changes: 19 additions & 3 deletions inc/js/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,25 @@ class MyLife extends Organization { // form=server
})
return experiences
}
async datacore(_mbr_id){
if(!_mbr_id || _mbr_id===this.mbr_id) throw new Error('datacore cannot be accessed')
return await this.factory.datacore(_mbr_id)
/**
* Challenges and logs in member.
* @param {string} memberId - Member id to challenge.
* @param {string} passphrase - Passphrase response to challenge.
* @returns {boolean} - Whether or not member is logged in successfully.
*/
async challengeAccess(memberId, passphrase){
const challengeSuccessful = await this.factory.challengeAccess(memberId, passphrase)
return challengeSuccessful
}
/**
* Returns the datacore object for the specified member id.
* @param {string} mbr_id - The Member id to access datacore
* @returns {Promise<object>} - Datacore object for member id
*/
async datacore(mbr_id){
if(!mbr_id || mbr_id===this.mbr_id)
throw new Error('datacore cannot be accessed')
return await this.factory.datacore(mbr_id)
}
/**
* Submits and returns the journal or diary entry to MyLife via API.
Expand Down
21 changes: 19 additions & 2 deletions inc/js/functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
/* module export functions */
async function about(ctx){
ctx.state.title = `About MyLife`
await ctx.render('about') // about
await ctx.render('about')
}
/**
* Activate a bot for the member
Expand Down Expand Up @@ -85,7 +85,13 @@ async function challenge(ctx){
const { mid, } = ctx.params
if(!mid?.length)
ctx.throw(400, `challenge request requires member id`)
ctx.body = await ctx.session.MemberSession.challengeAccess(mid, passphrase)
if(!ctx.state.MemberSession.locked)
return true
const challengeSuccessful = await ctx.MyLife.challengeAccess(mid, passphrase)
const { MemberSession, } = ctx.session
MemberSession.challengeOutcome = challengeSuccessful
await MemberSession.init(mid)
ctx.body = !MemberSession.locked
}
/**
* Chat with the member's avatar.
Expand Down Expand Up @@ -242,6 +248,16 @@ async function migrateChat(ctx){
const { avatar, } = ctx.state
ctx.body = await avatar.migrateChat(tid)
}
/**
* Given an itemId, obscures aspects of contents of the data record.
* @param {Koa} ctx - Koa Context object
* @returns {object} - The item obscured
*/
async function obscure(ctx){
const { iid, } = ctx.params
const { avatar, } = ctx.state
ctx.body = await avatar.obscure(iid)
}
/**
* Reset the passphrase for the member's avatar.
* @param {Koa} ctx - Koa Context object
Expand Down Expand Up @@ -416,6 +432,7 @@ export {
members,
migrateBot,
migrateChat,
obscure,
passphraseReset,
privacyPolicy,
retireBot,
Expand Down
19 changes: 18 additions & 1 deletion inc/js/globals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ const mAiJsFunctions = {
]
}
},
obscure: {
description: "Obscures a summary so that no human names are present.",
name: "obscure",
parameters: {
type: "object",
properties: {
itemId: {
description: "Id of summary to obscure",
format: "uuid",
type: "string"
}
},
required: [
"itemId"
]
}
},
storySummary: {
description: 'Generate a complete multi-paragraph STORY summary with keywords and other critical data elements.',
name: 'storySummary',
Expand Down Expand Up @@ -177,7 +194,7 @@ const mAiJsFunctions = {
},
required: [
"itemId",
"title"
"summary"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions inc/js/memory-functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async function livingMemory(ctx){
const { Globals, MyLife, } = ctx
const { avatar, } = ctx.state
if(!Globals.isValidGuid(iid))
return ctx.throw(400, 'Invalid Item ID')
ctx.throw(400, 'Invalid Item ID')
ctx.throw(501, 'Not Implemented')
ctx.body = await avatar.livingMemory(iid)
}
/* exports */
Expand All @@ -58,5 +59,4 @@ export {
improveMemory,
endMemory,
reliveMemory,
livingMemory,
}
Loading

0 comments on commit 76c3261

Please sign in to comment.