Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
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
11 changes: 10 additions & 1 deletion .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ blocks:
- name: Test
task:
jobs:
- name: Test
- name: Test (JWT)
commands:
- checkout
- sem-version node 12
Expand All @@ -17,5 +17,14 @@ blocks:
- cache store
- npm run build --if-present
- npm test
- name: Test (Repl Identity)
commands:
- checkout
- sem-version node 12
- cache restore
- npm install
- cache store
- npm run build --if-present
- USE_FILE=1 npm test
secrets:
- name: replit-database
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const fetch = require("node-fetch");
const fs = require("fs");

const replitDBFilename = "/tmp/replitdb"

class Client {
/**
Expand All @@ -7,7 +10,15 @@ class Client {
*/
constructor(key) {
if (key) this.key = key;
else this.key = process.env.REPLIT_DB_URL;
else {
// Try to read string from file, fall back to
// environment variable if it doesn't exist
try {
this.key = fs.readFileSync(replitDBFilename, "utf8");
} catch (err) {
this.key = process.env.REPLIT_DB_URL;
}
}
}

// Native Functions
Expand Down
9 changes: 5 additions & 4 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ const Client = require("./index");
let client;

beforeAll(async () => {
const pass = process.env.JWT_PASSWORD;
const resp = await fetch("https://database-test-jwt.util.repl.co", {
const pass = process.env.USE_FILE ? process.env.RIDT_PASSWORD : process.env.JWT_PASSWORD;
const url = process.env.USE_FILE ? "https://database-test-ridt.util.repl.co" : "https://database-test-jwt.util.repl.co";
const resp = await fetch(url, {
headers: {
Authorization: "Basic " + btoa("test:" + pass),
},
});
const url = await resp.text();
client = new Client(url);
const token = await resp.text();
client = new Client(token);
await client.empty();
});

Expand Down