@stoker-platform/cli 0.5.12
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/LICENSE.md +102 -0
- package/init-files/.##gitignore## +102 -0
- package/init-files/.devcontainer/devcontainer.json +14 -0
- package/init-files/.env/.env +70 -0
- package/init-files/.eslintrc.cjs +35 -0
- package/init-files/.firebaserc +6 -0
- package/init-files/.prettierignore +86 -0
- package/init-files/.prettierrc +5 -0
- package/init-files/bin/build.js +221 -0
- package/init-files/bin/shim.js +159 -0
- package/init-files/extensions/firestore-send-email.env +7 -0
- package/init-files/external.package.json +4 -0
- package/init-files/firebase-rules/database.rules.json +9 -0
- package/init-files/firebase-rules/firestore.custom.rules +19 -0
- package/init-files/firebase-rules/firestore.indexes.json +0 -0
- package/init-files/firebase-rules/firestore.rules +0 -0
- package/init-files/firebase-rules/storage.rules +0 -0
- package/init-files/firebase.hosting.json +122 -0
- package/init-files/firebase.json +52 -0
- package/init-files/functions/.##gitignore## +14 -0
- package/init-files/functions/.eslintrc.cjs +28 -0
- package/init-files/functions/package.json +46 -0
- package/init-files/functions/prompts/chat.prompt +17 -0
- package/init-files/functions/src/index.ts +457 -0
- package/init-files/functions/tsconfig.dev.json +3 -0
- package/init-files/functions/tsconfig.json +17 -0
- package/init-files/icons/logo-large.png +0 -0
- package/init-files/icons/logo-small.png +0 -0
- package/init-files/ops.js +25 -0
- package/init-files/package.json +53 -0
- package/init-files/project-data.json +5 -0
- package/init-files/remoteconfig.template.json +1 -0
- package/init-files/src/collections/Inbox.ts +444 -0
- package/init-files/src/collections/Outbox.ts +270 -0
- package/init-files/src/collections/Settings.ts +44 -0
- package/init-files/src/collections/Users.ts +138 -0
- package/init-files/src/main.ts +245 -0
- package/init-files/src/utils.ts +3 -0
- package/init-files/src/vite-env.d.ts +1 -0
- package/init-files/test/test.ts +5 -0
- package/init-files/tsconfig.json +23 -0
- package/init-files/vitest.config.ts +9 -0
- package/lib/package.json +45 -0
- package/lib/src/data/exportToBigQuery.js +41 -0
- package/lib/src/data/seedData.js +347 -0
- package/lib/src/deploy/applySchema.js +43 -0
- package/lib/src/deploy/cloud-functions/getFunctionsData.js +18 -0
- package/lib/src/deploy/deployProject.js +116 -0
- package/lib/src/deploy/firestore-export/exportFirestoreData.js +29 -0
- package/lib/src/deploy/firestore-ttl/deployTTLs.js +127 -0
- package/lib/src/deploy/live-update/liveUpdate.js +22 -0
- package/lib/src/deploy/maintenance/activateMaintenanceMode.js +9 -0
- package/lib/src/deploy/maintenance/disableMaintenanceMode.js +9 -0
- package/lib/src/deploy/maintenance/setDeploymentStatus.js +22 -0
- package/lib/src/deploy/rules-indexes/generateFirestoreIndexes.js +23 -0
- package/lib/src/deploy/rules-indexes/generateFirestoreRules.js +35 -0
- package/lib/src/deploy/rules-indexes/generateStorageRules.js +23 -0
- package/lib/src/deploy/schema/generateSchema.js +184 -0
- package/lib/src/deploy/schema/persistSchema.js +14 -0
- package/lib/src/lint/lintSchema.js +1491 -0
- package/lib/src/lint/securityReport.js +223 -0
- package/lib/src/main.js +460 -0
- package/lib/src/migration/firestore/migrateFirestore.js +8 -0
- package/lib/src/migration/firestore/operations/deleteField.js +58 -0
- package/lib/src/migration/migrateAll.js +30 -0
- package/lib/src/ops/auditDenormalized.js +124 -0
- package/lib/src/ops/auditPermissions.js +92 -0
- package/lib/src/ops/auditRelations.js +186 -0
- package/lib/src/ops/explainPreloadQueries.js +65 -0
- package/lib/src/ops/getUser.js +10 -0
- package/lib/src/ops/getUserPermissions.js +19 -0
- package/lib/src/ops/getUserRecord.js +20 -0
- package/lib/src/ops/listProjects.js +8 -0
- package/lib/src/ops/setUserCollection.js +14 -0
- package/lib/src/ops/setUserDocument.js +11 -0
- package/lib/src/ops/setUserRole.js +14 -0
- package/lib/src/project/addProject.js +935 -0
- package/lib/src/project/addRecord.js +9 -0
- package/lib/src/project/addRecordPrompt.js +205 -0
- package/lib/src/project/addTenant.js +59 -0
- package/lib/src/project/buildWebApp.js +10 -0
- package/lib/src/project/customDomain.js +157 -0
- package/lib/src/project/deleteProject.js +51 -0
- package/lib/src/project/deleteRecord.js +11 -0
- package/lib/src/project/deleteTenant.js +49 -0
- package/lib/src/project/getOne.js +25 -0
- package/lib/src/project/getSome.js +28 -0
- package/lib/src/project/initProject.js +16 -0
- package/lib/src/project/prepareEmulatorData.js +125 -0
- package/lib/src/project/setProject.js +13 -0
- package/lib/src/project/startEmulators.js +30 -0
- package/lib/src/project/updateRecord.js +9 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { initializeFirebase, runChildProcess } from "@stoker-platform/node-client";
|
|
2
|
+
import { getDatabase } from "firebase-admin/database";
|
|
3
|
+
import { mkdir, rm, writeFile } from "fs/promises";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
export const prepareEmulatorData = async () => {
|
|
6
|
+
if (!process.env.GCP_PROJECT) {
|
|
7
|
+
throw new Error("GCP_PROJECT not set.");
|
|
8
|
+
}
|
|
9
|
+
if (!process.env.FB_DATABASE) {
|
|
10
|
+
throw new Error("FB_DATABASE not set.");
|
|
11
|
+
}
|
|
12
|
+
if (!process.env.FB_AUTH_PASSWORD_POLICY) {
|
|
13
|
+
throw new Error("FB_AUTH_PASSWORD_POLICY not set.");
|
|
14
|
+
}
|
|
15
|
+
if (!process.env.FB_AUTH_PASSWORD_POLICY_UPGRADE) {
|
|
16
|
+
throw new Error("FB_AUTH_PASSWORD_POLICY_UPGRADE not set.");
|
|
17
|
+
}
|
|
18
|
+
const authConfig = {
|
|
19
|
+
signIn: {
|
|
20
|
+
email: {
|
|
21
|
+
enabled: true,
|
|
22
|
+
passwordRequired: true,
|
|
23
|
+
},
|
|
24
|
+
allowDuplicateEmails: false,
|
|
25
|
+
},
|
|
26
|
+
client: {
|
|
27
|
+
permissions: {
|
|
28
|
+
disabledUserSignup: true,
|
|
29
|
+
disabledUserDeletion: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
mfa: {
|
|
33
|
+
state: "ENABLED",
|
|
34
|
+
providerConfigs: [
|
|
35
|
+
{
|
|
36
|
+
state: "ENABLED",
|
|
37
|
+
totpProviderConfig: {
|
|
38
|
+
adjacentIntervals: 5,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
emailPrivacyConfig: {
|
|
44
|
+
enableImprovedEmailPrivacy: true,
|
|
45
|
+
},
|
|
46
|
+
passwordPolicyConfig: {
|
|
47
|
+
passwordPolicyEnforcementState: "ENFORCE",
|
|
48
|
+
forceUpgradeOnSignin: JSON.parse(process.env.FB_AUTH_PASSWORD_POLICY_UPGRADE),
|
|
49
|
+
passwordPolicyVersions: [
|
|
50
|
+
{
|
|
51
|
+
customStrengthOptions: JSON.parse(process.env.FB_AUTH_PASSWORD_POLICY),
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
autodeleteAnonymousUsers: true,
|
|
56
|
+
};
|
|
57
|
+
const authPath = join(process.cwd(), "firebase-emulator-data", "auth_export");
|
|
58
|
+
await mkdir(authPath, { recursive: true });
|
|
59
|
+
await writeFile(join(authPath, "config.json"), JSON.stringify(authConfig, null, 4));
|
|
60
|
+
await runChildProcess("firebase", [
|
|
61
|
+
"auth:export",
|
|
62
|
+
join(authPath, "accounts.json"),
|
|
63
|
+
"--project",
|
|
64
|
+
process.env.GCP_PROJECT,
|
|
65
|
+
]);
|
|
66
|
+
await initializeFirebase();
|
|
67
|
+
const rtdb = getDatabase();
|
|
68
|
+
const ref = rtdb.ref("schema");
|
|
69
|
+
const schemaSnapshot = await ref.orderByChild("published_time").limitToLast(1).get();
|
|
70
|
+
const schema = Object.values(schemaSnapshot.val())[0];
|
|
71
|
+
const databasePath = join(process.cwd(), "firebase-emulator-data", "database_export");
|
|
72
|
+
await mkdir(databasePath, { recursive: true });
|
|
73
|
+
await rm(databasePath, { recursive: true, force: true });
|
|
74
|
+
await mkdir(databasePath, { recursive: true });
|
|
75
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
76
|
+
await writeFile(join(databasePath, `${process.env.FB_DATABASE}.json`), JSON.stringify({
|
|
77
|
+
schema: {
|
|
78
|
+
"1": schema,
|
|
79
|
+
},
|
|
80
|
+
}, null, 4));
|
|
81
|
+
const storagePath = join(process.cwd(), "firebase-emulator-data", "storage_export");
|
|
82
|
+
await mkdir(storagePath, { recursive: true });
|
|
83
|
+
await mkdir(join(storagePath, "metadata"), { recursive: true });
|
|
84
|
+
await mkdir(join(storagePath, "blobs"), { recursive: true });
|
|
85
|
+
await writeFile(join(storagePath, `buckets.json`), JSON.stringify({
|
|
86
|
+
buckets: [
|
|
87
|
+
{
|
|
88
|
+
id: process.env.GCP_PROJECT,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
}, null, 4));
|
|
92
|
+
const firestorePath = join(process.cwd(), "firebase-emulator-data");
|
|
93
|
+
await runChildProcess("gcloud", [
|
|
94
|
+
"firestore",
|
|
95
|
+
"export",
|
|
96
|
+
`gs://${process.env.GCP_PROJECT}/firestore_export`,
|
|
97
|
+
"--project",
|
|
98
|
+
process.env.GCP_PROJECT,
|
|
99
|
+
]);
|
|
100
|
+
await runChildProcess("gcloud", [
|
|
101
|
+
"storage",
|
|
102
|
+
"cp",
|
|
103
|
+
"-r",
|
|
104
|
+
`gs://${process.env.GCP_PROJECT}/firestore_export`,
|
|
105
|
+
firestorePath,
|
|
106
|
+
]);
|
|
107
|
+
await runChildProcess("gcloud", ["storage", "rm", "-r", `gs://${process.env.GCP_PROJECT}/firestore_export`]);
|
|
108
|
+
const firebaseExportMetadata = {
|
|
109
|
+
firestore: {
|
|
110
|
+
path: "firestore_export",
|
|
111
|
+
metadata_file: "firestore_export/firestore_export.overall_export_metadata",
|
|
112
|
+
},
|
|
113
|
+
database: {
|
|
114
|
+
path: "database_export",
|
|
115
|
+
},
|
|
116
|
+
auth: {
|
|
117
|
+
path: "auth_export",
|
|
118
|
+
},
|
|
119
|
+
storage: {
|
|
120
|
+
path: "storage_export",
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
await writeFile(join(process.cwd(), "firebase-emulator-data", "firebase-export-metadata.json"), JSON.stringify(firebaseExportMetadata, null, 4));
|
|
124
|
+
process.exit();
|
|
125
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { runChildProcess } from "@stoker-platform/node-client";
|
|
2
|
+
export const setProject = async () => {
|
|
3
|
+
await runChildProcess("gcloud", [
|
|
4
|
+
"auth",
|
|
5
|
+
"application-default",
|
|
6
|
+
"set-quota-project",
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
8
|
+
process.env.GCP_PROJECT,
|
|
9
|
+
]).catch(() => {
|
|
10
|
+
throw new Error("Error setting quota project.");
|
|
11
|
+
});
|
|
12
|
+
process.exit();
|
|
13
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { runChildProcess } from "@stoker-platform/node-client";
|
|
2
|
+
export const startEmulators = async () => {
|
|
3
|
+
try {
|
|
4
|
+
await runChildProcess("genkit", [
|
|
5
|
+
"--non-interactive",
|
|
6
|
+
"start",
|
|
7
|
+
"--",
|
|
8
|
+
"firebase",
|
|
9
|
+
"emulators:start",
|
|
10
|
+
"--project",
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
+
process.env.GCP_PROJECT,
|
|
13
|
+
"--import",
|
|
14
|
+
`./firebase-emulator-data`,
|
|
15
|
+
], undefined, { ...process.env, FUNCTIONS_DISCOVERY_TIMEOUT: "30" });
|
|
16
|
+
process.exit();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error("Error starting the Firebase Emulator Suite.");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const startWebAppEmulators = async () => {
|
|
23
|
+
try {
|
|
24
|
+
await runChildProcess("npm", ["exec", "--package=@stoker-platform/web-app", "--", "start-web-app"]);
|
|
25
|
+
process.exit();
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new Error("Error starting the Firebase Hosting emulator.");
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { updateRecord as updateStokerRecord, initializeStoker } from "@stoker-platform/node-client";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
export const updateRecord = async (options) => {
|
|
5
|
+
await initializeStoker(options.mode || "production", options.tenant, join(process.cwd(), "lib", "main.js"), join(process.cwd(), "lib", "collections"));
|
|
6
|
+
const updatedRecord = await updateStokerRecord(options.path.split("/"), options.id, JSON.parse(options.data), options.userData ? JSON.parse(options.userData) : undefined, options.user);
|
|
7
|
+
console.log(JSON.stringify(updatedRecord, null, 2));
|
|
8
|
+
process.exit();
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/main.ts","../src/data/exporttobigquery.ts","../src/data/seeddata.ts","../src/deploy/applyschema.ts","../src/deploy/deployproject.ts","../src/deploy/cloud-functions/getfunctionsdata.ts","../src/deploy/firestore-export/exportfirestoredata.ts","../src/deploy/firestore-ttl/deployttls.ts","../src/deploy/live-update/liveupdate.ts","../src/deploy/maintenance/activatemaintenancemode.ts","../src/deploy/maintenance/disablemaintenancemode.ts","../src/deploy/maintenance/setdeploymentstatus.ts","../src/deploy/rules-indexes/generatefirestoreindexes.ts","../src/deploy/rules-indexes/generatefirestorerules.ts","../src/deploy/rules-indexes/generatestoragerules.ts","../src/deploy/schema/generateschema.ts","../src/deploy/schema/persistschema.ts","../src/lint/lintschema.ts","../src/lint/securityreport.ts","../src/migration/migrateall.ts","../src/migration/firestore/migratefirestore.ts","../src/migration/firestore/operations/deletefield.ts","../src/ops/auditdenormalized.ts","../src/ops/auditpermissions.ts","../src/ops/auditrelations.ts","../src/ops/explainpreloadqueries.ts","../src/ops/getuser.ts","../src/ops/getuserpermissions.ts","../src/ops/getuserrecord.ts","../src/ops/listprojects.ts","../src/ops/setusercollection.ts","../src/ops/setuserdocument.ts","../src/ops/setuserrole.ts","../src/project/addproject.ts","../src/project/addrecord.ts","../src/project/addrecordprompt.ts","../src/project/addtenant.ts","../src/project/buildwebapp.ts","../src/project/customdomain.ts","../src/project/deleteproject.ts","../src/project/deleterecord.ts","../src/project/deletetenant.ts","../src/project/getone.ts","../src/project/getsome.ts","../src/project/initproject.ts","../src/project/prepareemulatordata.ts","../src/project/setproject.ts","../src/project/startemulators.ts","../src/project/updaterecord.ts"],"version":"5.9.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stoker-platform/cli",
|
|
3
|
+
"version": "0.5.12",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
|
+
"main": "./lib/src/main.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"init-files",
|
|
10
|
+
"LICENSE.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "tsc --watch --preserveWatchOutput",
|
|
14
|
+
"lint": "tsc && eslint .",
|
|
15
|
+
"build": "tsc --build",
|
|
16
|
+
"test": "echo \"Error: no test specified\""
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"stoker": "./lib/src/main.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@faker-js/faker": "^10.1.0",
|
|
23
|
+
"@google-cloud/bigquery": "^8.1.1",
|
|
24
|
+
"@google-cloud/secret-manager": "^6.1.1",
|
|
25
|
+
"@google-cloud/storage": "^7.18.0",
|
|
26
|
+
"@inquirer/prompts": "^8.1.0",
|
|
27
|
+
"@stoker-platform/node-client": "0.5.9",
|
|
28
|
+
"@stoker-platform/types": "0.5.4",
|
|
29
|
+
"@stoker-platform/utils": "0.5.5",
|
|
30
|
+
"algoliasearch": "^5.46.2",
|
|
31
|
+
"commander": "^14.0.0",
|
|
32
|
+
"cross-spawn": "^7.0.6",
|
|
33
|
+
"dotenv": "^17.2.3",
|
|
34
|
+
"firebase-admin": "^13.6.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/cross-spawn": "^6.0.6",
|
|
38
|
+
"eslint-config-custom": "*",
|
|
39
|
+
"tsconfig": "*"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22",
|
|
43
|
+
"npm": "11"
|
|
44
|
+
}
|
|
45
|
+
}
|