Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffladiray committed Apr 18, 2023
1 parent b7c0ae9 commit 30ee6f7
Show file tree
Hide file tree
Showing 7 changed files with 1,653 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "MIT",
"scripts": {},
"private": true,
"dependencies": {},
"devDependencies": {
"nx": "15.9.2"
"nx": "15.9.2",
"typescript": "^5.0.4"
},
"workspaces": [
"packages/*"
Expand Down
674 changes: 674 additions & 0 deletions packages/live-demo-blocker/LICENSE

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions packages/live-demo-blocker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@forestadmin/woodshop-live-demo-blocker",
"version": "0.0.1",
"license": "GPL-3.0",
"main": "dist/index.js",
"publishConfig": {
"access": "public"
},
"devDependencies": {},
"scripts": {
"build": "tsc"
},
"dependencies": {
"@forestadmin/datasource-customizer": "^1.6.1"
}
}
30 changes: 30 additions & 0 deletions packages/live-demo-blocker/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {
CollectionCustomizer,
DataSourceCustomizer,
} from '@forestadmin/datasource-customizer';

type LiveDemoBlockerOptions = {
userEmail?: string;
errorMessage?: string;
}

export default (
dataSourceCustomizer: DataSourceCustomizer,
collectionCustomizer: CollectionCustomizer,
options: LiveDemoBlockerOptions = {},
) => {
const liveDemoUserEmail = options.userEmail || '[email protected]';
const liveDemoErrorMessage = options.errorMessage || 'You can only read data on this live demo.';

function blockCallIfLiveDemoUser(context) {
if (liveDemoUserEmail === context.caller.email) {
context.throwForbiddenError(liveDemoErrorMessage);
}
}

dataSourceCustomizer.collections.forEach(collection => {
collection.addHook('Before', 'Update', blockCallIfLiveDemoUser);
collection.addHook('Before', 'Delete', blockCallIfLiveDemoUser);
collection.addHook('Before', 'Create', blockCallIfLiveDemoUser);
});
};
7 changes: 7 additions & 0 deletions packages/live-demo-blocker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/*"]
}
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "ES2020",
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"inlineSourceMap": true,
"noImplicitOverride": true,
"stripInternal": true,
"skipLibCheck": true
}
}
Loading

0 comments on commit 30ee6f7

Please sign in to comment.