Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child and past sessions data #18

Merged
merged 11 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
863 changes: 516 additions & 347 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"homepage": "https://github.com/lookit/lookit-jspsych#readme",
"dependencies": {
"@changesets/cli": "^2.27.1",
"@lookit/lookit-initjspsych": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"eslint": "^8.55.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/lookit-api/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require("@jspsych/config/jest").makePackageConfig(__dirname);
config.moduleNameMapper = {};
module.exports = config;
21 changes: 21 additions & 0 deletions packages/lookit-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@lookit/lookit-api",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"test": "jest --coverage",
"build": "rollup --config",
"schema": "openapi-typescript ../../../lookit-api/openapi-schema.yml -o ./src/schema.d.ts"
},
"unpkg": "dist/index.browser.min.js",
"files": [
"src",
"dist"
],
"author": "",
"license": "ISC",
"dependencies": {
"@jspsych/config": "^2.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/lookit-api/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeRollupConfig } from "@jspsych/config/rollup";

export default makeRollupConfig("lookitAPI");
12 changes: 12 additions & 0 deletions packages/lookit-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiResponse, Child, PastSession } from "./types";
import { get } from "./utils";

async function retrieveChild(uuid: string) {
return (await get<ApiResponse<Child>>(`children/${uuid}/`)).data;
}

async function retrievePastSessions(uuid: string) {
return (await get<ApiResponse<PastSession[]>>(`past-sessions/${uuid}/`)).data;
}

export default { retrieveChild, retrievePastSessions };
76 changes: 76 additions & 0 deletions packages/lookit-api/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
type Relationship = {
links: {
related: string;
};
};

type Attributes = {
readonly pk?: number;
readonly url?: string;
};

interface Relationships {}

interface ChildAttrs extends Attributes {
given_name: string;
birthday: string;
gender: "m" | "f" | "o" | "na";
readonly age_at_birth?: string;
additional_information?: string;
readonly language_list?: string;
readonly condition_list?: string;
deleted?: boolean;
former_lookit_profile_id?: string;
readonly pk?: number;
}

interface PastSessionAttrs extends Attributes {
conditions?: Record<string, never>;
global_event_timings?: Record<string, never>;
exp_data?: Record<string, never>;
sequence?: string[];
completed?: boolean;
completed_consent_frame?: boolean;
survey_consent?: boolean;
readonly created_on?: string;
is_preview?: boolean;
readonly hash_child_id?: string;
recording_method?: string;
eligibility?: (
| "Eligible"
| "Ineligible_TooYoung"
| "Ineligible_TooOld"
| "Ineligible_CriteriaExpression"
| "Ineligible_Participation"
)[];
}

interface Data<Attributes> {
type: string;
id: string;
attributes: Attributes;
relationships: Relationships;
links: {
self: string;
};
}

export interface ApiResponse<Data> {
data: Data;
}

export interface Child extends Data<ChildAttrs> {
type: "children";
relationships: {
user: Relationship;
};
}
export interface PastSession extends Data<PastSessionAttrs> {
type: "past_sessions";
relationships: {
child: Relationship;
user: Relationship;
study: Relationship;
demographic_snapshot: Relationship;
};
}
15 changes: 15 additions & 0 deletions packages/lookit-api/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const url_base = "/api/v2/";

export async function get<T>(url: string) {
/**
* Function for REST get.
*/

const request = new Request(url_base + url, {
method: "GET",
mode: "same-origin",
});

const response = await fetch(request);
return response.json() as Promise<T>;
}
8 changes: 8 additions & 0 deletions packages/lookit-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@jspsych/config/tsconfig.core.json",
"compilerOptions": {
"strict": true,
"baseUrl": "."
},
"include": ["src"]
}
3 changes: 3 additions & 0 deletions packages/lookit-helpers/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require("@jspsych/config/jest").makePackageConfig(__dirname);
config.moduleNameMapper = {};
module.exports = config;
21 changes: 21 additions & 0 deletions packages/lookit-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@lookit/lookit-helpers",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --coverage",
"build": "rollup --config"
},
"unpkg": "dist/index.browser.min.js",
"files": [
"src",
"dist"
],
"author": "",
"license": "ISC",
"dependencies": {
"@jspsych/config": "^2.0.0",
"@lookit/lookit-api": "^1.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/lookit-helpers/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeRollupConfig } from "@jspsych/config/rollup";

export default makeRollupConfig("lookitHelpers");
14 changes: 14 additions & 0 deletions packages/lookit-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import api from "@lookit/lookit-api";

async function child(uuid: string) {
const child = await api.retrieveChild(uuid);
const { given_name, birthday, age_at_birth, additional_information } =
child.attributes;
return { given_name, birthday, age_at_birth, additional_information };
}

async function pastSessions(response_uuid: string) {
return await api.retrievePastSessions(response_uuid);
}

export default { child, pastSessions };
8 changes: 8 additions & 0 deletions packages/lookit-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@jspsych/config/tsconfig.core.json",
"compilerOptions": {
"strict": true,
"baseUrl": "."
},
"include": ["src"]
}
Loading