token-saver-cc 1.0.0 → 1.0.2

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/.firebaserc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "projects": {
3
+ "default": "clipmachinery"
4
+ }
5
+ }
package/firebase.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "functions": [
3
+ {
4
+ "source": "functions",
5
+ "codebase": "default",
6
+ "disallowLegacyRuntimeConfig": true,
7
+ "ignore": [
8
+ "node_modules",
9
+ ".git",
10
+ "firebase-debug.log",
11
+ "firebase-debug.*.log",
12
+ "*.local"
13
+ ]
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,28 @@
1
+ module.exports = {
2
+ env: {
3
+ es6: true,
4
+ node: true,
5
+ },
6
+ parserOptions: {
7
+ "ecmaVersion": 2018,
8
+ },
9
+ extends: [
10
+ "eslint:recommended",
11
+ "google",
12
+ ],
13
+ rules: {
14
+ "no-restricted-globals": ["error", "name", "length"],
15
+ "prefer-arrow-callback": "error",
16
+ "quotes": ["error", "double", {"allowTemplateLiterals": true}],
17
+ },
18
+ overrides: [
19
+ {
20
+ files: ["**/*.spec.*"],
21
+ env: {
22
+ mocha: true,
23
+ },
24
+ rules: {},
25
+ },
26
+ ],
27
+ globals: {},
28
+ };
@@ -0,0 +1,65 @@
1
+ const functions = require("firebase-functions");
2
+ const admin = require("firebase-admin");
3
+
4
+ admin.initializeApp();
5
+
6
+ const corsHandler = (req, res, next) => {
7
+ res.set("Access-Control-Allow-Origin", "*");
8
+ res.set("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
9
+ res.set("Access-Control-Allow-Headers", "Content-Type");
10
+
11
+ if (req.method === "OPTIONS") {
12
+ res.status(204).send("");
13
+ } else {
14
+ next();
15
+ }
16
+ };
17
+
18
+ exports.validateLicense = functions.https.onRequest((req, res) => {
19
+ corsHandler(req, res, async () => {
20
+ if (req.method !== "POST") {
21
+ return res.status(405).json({ error: "Method not allowed" });
22
+ }
23
+
24
+ const { key } = req.body;
25
+
26
+ if (!key) {
27
+ return res.status(400).json({ valid: false, tier: "free" });
28
+ }
29
+
30
+ try {
31
+ const snapshot = await admin
32
+ .firestore()
33
+ .collection("licenses")
34
+ .where("key", "==", key)
35
+ .get();
36
+
37
+ if (snapshot.empty) {
38
+ return res.status(403).json({ valid: false, tier: "free" });
39
+ }
40
+
41
+ const license = snapshot.docs[0].data();
42
+
43
+ if (!license.valid) {
44
+ return res.status(403).json({ valid: false, tier: "free" });
45
+ }
46
+
47
+ if (license.expires) {
48
+ const expireDate = new Date(license.expires);
49
+ if (expireDate < new Date()) {
50
+ return res.status(403).json({ valid: false, tier: "free" });
51
+ }
52
+ }
53
+
54
+ return res.json({
55
+ valid: true,
56
+ tier: license.tier,
57
+ email: license.email,
58
+ expires: license.expires,
59
+ });
60
+ } catch (error) {
61
+ console.error("Error:", error);
62
+ return res.json({ valid: false, tier: "free" });
63
+ }
64
+ });
65
+ });