Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
90 changes: 90 additions & 0 deletions .type_check.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
src/app_store_receipt_verifier.js(86,57): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
src/index.js(12,32): error TS2307: Cannot find module 'nostr-tools/pool' or its corresponding type declarations.
src/index.js(36,34): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(37,30): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(38,41): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(39,43): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(40,30): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(41,39): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(42,31): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/index.js(43,30): error TS2345: Argument of type 'string' is not assignable to parameter of type 'DatabaseOptions & { name: string; }'.
Type 'string' is not assignable to type '{ name: string; }'.
src/invoicing.js(187,53): error TS2554: Expected 0 arguments, but got 1.
src/nip98_auth.js(25,5): error TS2304: Cannot find name 'auth_header_parts'.
src/nip98_auth.js(26,9): error TS2304: Cannot find name 'auth_header_parts'.
src/nip98_auth.js(30,9): error TS2304: Cannot find name 'auth_header_parts'.
src/translate.js(110,36): error TS2538: Type 'Buffer' cannot be used as an index type.
src/web_auth.js(7,35): error TS2307: Cannot find module 'nostr-tools/pure' or its corresponding type declarations.
src/web_auth.js(9,48): error TS2307: Cannot find module 'nostr-tools/pool' or its corresponding type declarations.
src/web_auth.js(11,32): error TS2307: Cannot find module 'nostr-tools/pool' or its corresponding type declarations.
src/web_auth.js(43,25): error TS2365: Operator '+' cannot be applied to types 'number' and 'string | number'.
test/controllers/mock_iap_controller.js(85,60): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
test/controllers/purple_test_controller.js(49,5): error TS2322: Type 'boolean' is not assignable to type 'string'.
test/controllers/purple_test_controller.js(55,5): error TS2322: Type 'number' is not assignable to type 'string'.
test/controllers/purple_test_controller.js(56,5): error TS2322: Type 'number' is not assignable to type 'string'.
test/controllers/purple_test_controller.js(57,5): error TS2322: Type 'number' is not assignable to type 'string'.
test/otp_login.test.js(104,90): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
test/otp_login.test.js(134,21): error TS2365: Operator '<' cannot be applied to types 'number' and 'string'.
test/otp_login.test.js(186,44): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
test/otp_login.test.js(239,44): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
test/transaction_management.test.js(34,45): error TS2345: Argument of type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(63,45): error TS2345: Argument of type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(92,45): error TS2345: Argument of type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(121,45): error TS2345: Argument of type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(150,45): error TS2345: Argument of type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(186,45): error TS2345: Argument of type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(204,45): error TS2345: Argument of type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(230,45): error TS2345: Argument of type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(256,45): error TS2345: Argument of type '({ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; })[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(307,45): error TS2345: Argument of type '({ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; })[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(385,45): error TS2345: Argument of type '({ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; } | { ...; })[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; } | { ...; }' is not assignable to type 'Transaction'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(430,45): error TS2345: Argument of type '({ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; })[]' is not assignable to parameter of type 'Transaction[]'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; } | { type: string; id: any; start_date: any; end_date: any; purchased_date: number; duration: number; }' is not assignable to type 'Transaction'.
Type '{ type: string; id: string; start_date: number; end_date: number; purchased_date: number; duration: any; }' is not assignable to type 'Transaction'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"iap" | "ln" | "legacy"'.
test/transaction_management.test.js(436,10): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
test/translate.test.js(7,27): error TS2305: Module '"./controllers/utils"' has no exported member 'TEST_BASE_URL'.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The Damus API backend for Damus Purple and other functionality.

- `DB_PATH`: Path to the folder where to save mdb files.
- `TESTFLIGHT_URL`: URL for the TestFlight app (optional)
- `NOTEDECK_INSTALL_MD`: URL for the notedeck installation instructions markdown
- `NO_AUTH_WALL_NOTEDECK_INSTALL`: Disables the authentication wall for the notedeck installation instructions when set to `"true"`.
- `NOTEDECK_INSTALL_MD`: Path to the freely available notedeck installation instructions (markdown file)
- `NOTEDECK_INSTALL_PREMIUM_MD`: Path to the premium notedeck installation instructions (markdown file)

#### Translations

Expand Down
15 changes: 15 additions & 0 deletions notedeck-install-instructions-premium.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Installing Notedeck

Thank you for your interest in the Notedeck Beta release! We are excited to have you try out our software. Below are the instructions for installing Notedeck on your system.

If you encounter any issues, please [contact us]([email protected]).

## Binaries

Please find the download link for your operating system below.

- macOS (Apple Silicon): [notedeck_macos_silicon.dmg](#)
- macOS (Intel): [notedeck_macos_intel.dmg](#)
- Linux Debian package: [notedeck_linux_debian.deb](#)
- Linux x86 generic: [notedeck_linux_generic.zip](#)
- Linux ARM generic: [notedeck_linux_generic.zip](#)
2 changes: 2 additions & 0 deletions notedeck-install-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Thank you for your interest in the Notedeck Alpha release! We are excited to have you try out our software. Below are the instructions for installing Notedeck on your system.

If you are a Purple user, you can now access our beta release! To access the beta install instructions, click [here](/purple/login).

If you encounter any issues, please [contact us]([email protected]).

## Binaries
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"dev": "TRANSLATION_PROVIDER=mock ENABLE_HTTP_AUTH=\"true\" node src/index.js",
"dev-debug": "TRANSLATION_PROVIDER=mock ENABLE_HTTP_AUTH=\"true\" node --inspect src/index.js",
"dev-debug-cli": "TRANSLATION_PROVIDER=mock ENABLE_HTTP_AUTH=\"true\" node inspect src/index.js",
"type-check": "tsc --checkJs --allowJs src/*.js --noEmit --skipLibCheck",
"type-check": "tsc --checkJs --allowJs src/*.js test/*.js --noEmit --skipLibCheck",
"type-check-compare": "tsc --checkJs --allowJs src/*.js test/*.js --noEmit --skipLibCheck > .type_check.txt",
"type-check-path": "tsc --checkJs --allowJs --noEmit --skipLibCheck"
},
"dependencies": {
Expand Down
44 changes: 23 additions & 21 deletions src/router_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,26 +445,28 @@ function config_router(app) {
return
});

if(process.env.NO_AUTH_WALL_NOTEDECK_INSTALL == "true") {
router.get('/notedeck-install-instructions', async (req, res) => {
provide_notedeck_instructions(req, res)
});
}
else {
router.get('/notedeck-install-instructions', app.web_auth_manager.require_web_auth.bind(app.web_auth_manager), async (req, res) => {
const pubkey = req.authorized_pubkey
const { account, user_id } = get_account_and_user_id(app, pubkey)
if (!account) {
simple_response(res, 401)
return
}
const account_info = get_account_info_payload(user_id, account, true)
if(account_info.active == true) {
provide_notedeck_instructions(req, res)
}
router.get('/notedeck-install-instructions', app.web_auth_manager.use_web_auth.bind(app.web_auth_manager), async (req, res) => {
if(!req.authorized_pubkey) {
provide_notedeck_instructions(req, res, false) // Provides free download instructions
return
});
}
}

const { account, user_id } = get_account_and_user_id(app, req.authorized_pubkey)
if (!account) {
simple_response(res, 401)
return
}

const account_info = get_account_info_payload(user_id, account, true)
if (account_info.active == true) {
provide_notedeck_instructions(req, res, true) // Provide premium download instructions
return
}
else {
provide_notedeck_instructions(req, res, false) // Provide free download instructions
return
}
});

// MARK: Admin routes

Expand Down Expand Up @@ -681,8 +683,8 @@ function get_allowed_cors_origins() {
}
}

async function provide_notedeck_instructions(req, res) {
const installInstructionsPath = path.resolve(process.env.NOTEDECK_INSTALL_MD);
async function provide_notedeck_instructions(req, res, user_authenticated) {
const installInstructionsPath = user_authenticated == true ? path.resolve(process.env.NOTEDECK_INSTALL_PREMIUM_MD) : path.resolve(process.env.NOTEDECK_INSTALL_MD);
try {
const installInstructions = fs.readFileSync(installInstructionsPath, { encoding: 'utf8' });
json_response(res, { value: installInstructions });
Expand Down
47 changes: 45 additions & 2 deletions src/web_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class WebAuthManager {
this.dbs = dbs
this.pool = pool
this.otp_max_tries = process.env.OTP_MAX_TRIES || DEFAULT_OTP_MAX_TRIES
this.session_expiry = process.env.SESSION_EXPIRY || DEFAULT_SESSION_EXPIRY
this.session_expiry = parseInt(process.env.SESSION_EXPIRY) || DEFAULT_SESSION_EXPIRY
this.otp_expiry = process.env.OTP_EXPIRY || DEFAULT_OTP_EXPIRY
}

Expand Down Expand Up @@ -128,7 +128,7 @@ class WebAuthManager {
// MARK: Middleware

/**
* Middleware to check if a user is authenticated
* Middleware to check and require a user to be authenticated
* @param {object} req - The Express request object
* @param {object} res - The Express response object
* @param {function} next - The next middleware function
Expand Down Expand Up @@ -167,6 +167,49 @@ class WebAuthManager {
req.authorized_pubkey = session_data.pubkey;
next();
}

/**
* Middleware to check if a user is authenticated, but does not require authentication
* @param {object} req - The Express request object
* @param {object} res - The Express response object
* @param {function} next - The next middleware function
*/
async use_web_auth(req, res, next) {
const auth_header = req.header('Authorization');

if (!auth_header) {
next();
return;
}

const [auth_type, token] = auth_header.split(' ');
if (auth_type !== 'Bearer') {
next();
return;
}

if (!token) {
next();
return;
}

const session_data = await this.dbs.sessions.get(token);
if (!session_data) {
next();
return;
}

// Check if the session has expired
if (current_time() - session_data.created_at > this.session_expiry) {
next();
return;
}

// User authenticated!

req.authorized_pubkey = session_data.pubkey;
next();
}
}


Expand Down
12 changes: 11 additions & 1 deletion test/controllers/purple_test_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ class PurpleTestClient {
return await this.get('/accounts/' + this.public_key, options)
}

/**
* Gets the notedeck install instructions
*
* @param {PurpleTestClientRequestOptions} options - The request options
* @returns {Promise<Object>} The response
*/
async get_notedeck_install_instructions(options = {}) {
return await this.get('/notedeck-install-instructions', options)
}

/**
* Gets the product template options.
*
*
* @param {PurpleTestClientRequestOptions} options - The request options
* @returns {Promise<Object>} The product information
*/
Expand Down
21 changes: 19 additions & 2 deletions test/controllers/purple_test_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class PurpleTestController {
process.env.OTP_EXPIRY = 60*5
process.env.TESTFLIGHT_URL = "https://testflight.apple.com/join/abc123"
process.env.NOTEDECK_INSTALL_MD = "./notedeck-install-instructions.md"
process.env.NOTEDECK_INSTALL_PREMIUM_MD = "./notedeck-install-instructions-premium.md"
this.env = process.env
}

setup_stubs() {
Expand Down Expand Up @@ -193,8 +195,23 @@ class PurpleTestController {
const check_invoice_status_response = await this.clients[pubkey].check_invoice(verify_checkout_response.body.id);
this.t.same(check_invoice_status_response.status, 200)
}



async login(pubkey) {
// Let's request an OTP
const test_otp = "432931";
this.web_auth_controller.set_next_random_otp(test_otp);
const otp_response = await this.clients[pubkey].request_otp();
this.t.same(otp_response.statusCode, 200);
this.t.same(otp_response.body, { success: true });

// Login with the correct OTP
const login_response = await this.clients[pubkey].verify_otp(test_otp);
this.t.same(login_response.statusCode, 200);
this.t.same(login_response.body.valid, true);
this.t.ok(login_response.body.session_token);
return login_response.body.session_token
}

// MARK: - Account UUID control

/**
Expand Down
Loading
Loading