meetfy 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -39092,6 +39092,11 @@ function clearConfig() {
|
|
|
39092
39092
|
// src/auth.ts
|
|
39093
39093
|
var WORKER_URL = (process.env.MEETFY_AUTH_URL ?? "https://meetfy.eduardoborges.dev").replace(/\/$/, "");
|
|
39094
39094
|
var REDIRECT_PORT = 3434;
|
|
39095
|
+
function storeFreshTokens(tokens) {
|
|
39096
|
+
const expiresIn = tokens.expires_in;
|
|
39097
|
+
const expiry_date = typeof expiresIn === "number" ? Date.now() + expiresIn * 1e3 : typeof tokens.expiry_date === "number" ? tokens.expiry_date : void 0;
|
|
39098
|
+
return { ...tokens, expiry_date };
|
|
39099
|
+
}
|
|
39095
39100
|
var HTML_OK = `
|
|
39096
39101
|
<!DOCTYPE html>
|
|
39097
39102
|
<html>
|
|
@@ -39125,19 +39130,22 @@ function makeClient(clientId, tokens) {
|
|
|
39125
39130
|
return client;
|
|
39126
39131
|
}
|
|
39127
39132
|
async function getClient() {
|
|
39128
|
-
const
|
|
39133
|
+
const storedRaw = getConfig("googleTokens");
|
|
39129
39134
|
const clientId = getConfig("googleClientId");
|
|
39130
|
-
if (!
|
|
39131
|
-
let tokens =
|
|
39132
|
-
|
|
39135
|
+
if (!storedRaw || !clientId) return null;
|
|
39136
|
+
let tokens = { ...storedRaw };
|
|
39137
|
+
const skewMs = 6e4;
|
|
39138
|
+
const expired = !tokens.expiry_date || Date.now() > tokens.expiry_date - skewMs;
|
|
39139
|
+
if (expired && tokens.refresh_token) {
|
|
39133
39140
|
try {
|
|
39134
39141
|
const res = await fetch(`${WORKER_URL}/refresh`, {
|
|
39135
39142
|
method: "POST",
|
|
39136
39143
|
headers: { "Content-Type": "application/json" },
|
|
39137
|
-
body: JSON.stringify({ refresh_token:
|
|
39144
|
+
body: JSON.stringify({ refresh_token: tokens.refresh_token })
|
|
39138
39145
|
});
|
|
39139
39146
|
if (res.ok) {
|
|
39140
|
-
|
|
39147
|
+
const fresh = await res.json();
|
|
39148
|
+
tokens = storeFreshTokens({ ...tokens, ...fresh });
|
|
39141
39149
|
setConfig("googleTokens", tokens);
|
|
39142
39150
|
}
|
|
39143
39151
|
} catch {
|
|
@@ -39185,10 +39193,11 @@ function waitForTokensThenSave(port) {
|
|
|
39185
39193
|
const json2 = Buffer.from(raw, "base64").toString("utf-8");
|
|
39186
39194
|
const { client_id: clientId, ...tokens } = JSON.parse(json2);
|
|
39187
39195
|
if (!clientId || !tokens.access_token) throw new Error("Incomplete payload");
|
|
39196
|
+
const saved = storeFreshTokens(tokens);
|
|
39188
39197
|
res.writeHead(200, { "Content-Type": "text/html", Connection: "close" }).end(HTML_OK);
|
|
39189
|
-
setConfig("googleTokens",
|
|
39198
|
+
setConfig("googleTokens", saved);
|
|
39190
39199
|
setConfig("googleClientId", clientId);
|
|
39191
|
-
once2(null, makeClient(clientId,
|
|
39200
|
+
once2(null, makeClient(clientId, saved));
|
|
39192
39201
|
server.close();
|
|
39193
39202
|
} catch {
|
|
39194
39203
|
res.writeHead(400, { "Content-Type": "text/plain", Connection: "close" }).end("Invalid tokens");
|
|
@@ -39988,7 +39997,7 @@ function copyAndOpenUrl(url) {
|
|
|
39988
39997
|
|
|
39989
39998
|
// package.json
|
|
39990
39999
|
var package_default = {
|
|
39991
|
-
version: "1.0.
|
|
40000
|
+
version: "1.0.8"};
|
|
39992
40001
|
|
|
39993
40002
|
// src/cli.ts
|
|
39994
40003
|
function json(obj) {
|