forked from tsai/budibase
389 changed files with 7120 additions and 5675 deletions
@ -0,0 +1,214 @@ |
|||||
|
<p align="center"> |
||||
|
<a href="https://www.budibase.com"> |
||||
|
<img alt="Budibase" src="https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg" width="60" /> |
||||
|
</a> |
||||
|
</p> |
||||
|
<h1 align="center"> |
||||
|
Budibase |
||||
|
</h1> |
||||
|
|
||||
|
<h3 align="center"> |
||||
|
使って楽しいローコードプラットフォーム |
||||
|
</h3> |
||||
|
<p align="center"> |
||||
|
Budibaseはオープンソースのローコードプラットフォームで、生産性を向上させるツールを簡単に構築することができます。 |
||||
|
</p> |
||||
|
|
||||
|
<h3 align="center"> |
||||
|
🤖 🎨 🚀 |
||||
|
</h3> |
||||
|
<br> |
||||
|
|
||||
|
<p align="center"> |
||||
|
<img alt="Budibase design ui" src="https://res.cloudinary.com/daog6scxm/image/upload/v1633524049/ui/design-ui-wide-mobile_gdaveq.jpg"> |
||||
|
</p> |
||||
|
|
||||
|
<p align="center"> |
||||
|
<a href="https://github.com/Budibase/budibase/releases"> |
||||
|
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/Budibase/budibase/total"> |
||||
|
</a> |
||||
|
<a href="https://github.com/Budibase/budibase/releases"> |
||||
|
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/Budibase/budibase"> |
||||
|
</a> |
||||
|
<a href="https://twitter.com/intent/follow?screen_name=budibase"> |
||||
|
<img src="https://img.shields.io/twitter/follow/budibase?style=social" alt="Follow @budibase" /> |
||||
|
</a> |
||||
|
<img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Code of conduct" /> |
||||
|
<a href="https://codecov.io/gh/Budibase/budibase"> |
||||
|
<img src="https://codecov.io/gh/Budibase/budibase/graph/badge.svg?token=E8W2ZFXQOH"/> |
||||
|
</a> |
||||
|
</p> |
||||
|
|
||||
|
<h3 align="center"> |
||||
|
<a href="https://docs.budibase.com/getting-started">はじめに</a> |
||||
|
<span> · </span> |
||||
|
<a href="https://docs.budibase.com">ドキュメント</a> |
||||
|
<span> · </span> |
||||
|
<a href="https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas">機能リクエスト</a> |
||||
|
<span> · </span> |
||||
|
<a href="https://github.com/Budibase/budibase/issues">バグ報告</a> |
||||
|
<span> · </span> |
||||
|
サポート: <a href="https://github.com/Budibase/budibase/discussions">ディスカッション</a> |
||||
|
</h3> |
||||
|
|
||||
|
<br /><br /> |
||||
|
## ✨ 特徴 |
||||
|
|
||||
|
### "本物"のソフトウェアを構築できます |
||||
|
ほかのプラットフォームとは違い、Budibaseだけでシングルページのアプリケーションを制作し完成させることができます。Budibaseで作られたアプリケーションは素晴らしいパフォーマンスを持っており、レスポンシブデザインにも対応しています。ユーザー達にいい印象を与えること間違いなしでしょう! |
||||
|
<br /><br /> |
||||
|
|
||||
|
### 拡張性が高くオープンソース |
||||
|
Budibaseはオープンソースで、GPL v3ライセンスの下に公開されています。このことは、Budibaseが常にあなたのそばにいるという安心感を与えてくれることでしょう。そして、私たちは開発者に優しい環境を提供しているので、あなたは好きなだけにソースコードをフォークして改造、もしくは直接Budibaseにコントリビュートすることができます。 |
||||
|
<br /><br /> |
||||
|
|
||||
|
### 既存のデータ、もしくは一から始める |
||||
|
Budibaseはいろんなツールから既存のデータを使用できます。たとえばMongoDB、CouchDB、 PostgreSQL、MySQL、Airtable、S3、DynamoDB、REST APIなど。ほかのプラットフォームにない特徴として、Budibaseはデータなしの状態でビジネスアプリケーションの構築を一から始めることができます。 [新しいデータリソースをリクエスト](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas)。 |
||||
|
|
||||
|
<p align="center"> |
||||
|
<img alt="Budibase data" src="https://res.cloudinary.com/daog6scxm/image/upload/v1636970242/Out%20of%20beta%20launch/data_n1tlhf.png"> |
||||
|
</p> |
||||
|
<br /><br /> |
||||
|
|
||||
|
### パワフルな内蔵コンポーネントでアプリケーションを設計し構築 |
||||
|
|
||||
|
Budibaseには、美しくデザインされた強力なコンポーネントが付属しており、それら使用しUIを簡単に構築することができます。また、CSSによるスタイリングオプションも豊富に用意されているので、よりクリエイティブな表現もも可能です。 |
||||
|
[Request new component](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas)。 |
||||
|
|
||||
|
<p align="center"> |
||||
|
<img alt="Budibase design" src="https://res.cloudinary.com/daog6scxm/image/upload/v1636970243/Out%20of%20beta%20launch/design-like-a-pro_qhlfeu.gif"> |
||||
|
</p> |
||||
|
<br /><br /> |
||||
|
|
||||
|
### プロセスを自動化し、ほかのツールと連携し、Webhookをでつながる! |
||||
|
定型化した作業を自動化して時間を節約しましょう。Webhookに接続、Eメールの自動送信など、すべてBudibaseに任せましょう。 こちらで簡単に [新しいオートメーションを作る](https://github.com/Budibase/automations)または[新しいオートメーションをリクエストすることができます](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas)。 |
||||
|
|
||||
|
<p align="center"> |
||||
|
<img alt="Budibase automations" src="https://res.cloudinary.com/daog6scxm/image/upload/v1636970486/Out%20of%20beta%20launch/automation_riro7u.png"> |
||||
|
</p> |
||||
|
<br /><br /> |
||||
|
|
||||
|
### 使い親しんだツールとの統合 |
||||
|
Budibaseは多くの人気ツールと統合されており、あなたのニーズに合わせたパーフェクトなアプリケーションを構築することができます。 |
||||
|
|
||||
|
<p align="center"> |
||||
|
<img alt="Budibase integrations" src="https://res.cloudinary.com/daog6scxm/image/upload/v1636970242/Out%20of%20beta%20launch/integrations_kc7dqt.png"> |
||||
|
</p> |
||||
|
<br /><br /> |
||||
|
|
||||
|
### 管理者のパラダイス |
||||
|
Budibaseはどんな規模のプロジェクトにも柔軟に対応できます。Budibaseを使えば、個人または組織のサーバーでセルフホスティングし、ユーザー、オンボーディング、SMTP、アプリ、グループ、テーマなどをひとまとめに管理することが可能です。また、ユーザーやグループにアプリポータルを提供し、グループ管理者にユーザー管理を委ねることも可能です。 |
||||
|
- プロモーションビデオを視聴する: https://youtu.be/xoljVpty_Kw |
||||
|
|
||||
|
<br /><br /><br /> |
||||
|
|
||||
|
## 🏁 始めましょう |
||||
|
|
||||
|
<a href="https://docs.budibase.com/self-hosting/self-host"><img src="https://res.cloudinary.com/daog6scxm/image/upload/v1634808888/logo/deploy_npl9za.png" /></a> |
||||
|
|
||||
|
Docker、KubernetesもしくはDegital Oceanを使用しセルフホスティングするか、セルフホスティングに困難がある、もしくは今すぐ開始したい場合はBudibase Cloudを使用しすぐに始めましょう。 |
||||
|
|
||||
|
### [Budibaseをセルフホスティングする](https://docs.budibase.com/self-hosting/self-host) |
||||
|
|
||||
|
### [Budibase Cloudを使用する](https://budibase.com) |
||||
|
|
||||
|
|
||||
|
<br /><br /> |
||||
|
|
||||
|
## 🎓 Budibaseを学ぶ |
||||
|
|
||||
|
Budibaseのドキュメント[はここです](https://docs.budibase.com)。 |
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
<br /><br /> |
||||
|
|
||||
|
## 💬 コミュニティ |
||||
|
|
||||
|
もし何か問題がある、もしくはBudibaseコミュニティのほかのユーザーと交流したいのであれば私たちの[Github discussions](https://github.com/Budibase/budibase/discussions)までお越しください。 |
||||
|
|
||||
|
<br /><br /><br /> |
||||
|
|
||||
|
|
||||
|
## ❗ 行動規範 |
||||
|
|
||||
|
Budibase は、すべての人を歓迎し、多様で、ハラスメントのない環境を提供することに尽力しています。Budibase コミュニティに参加するすべての人たちが私たちの[**行動規範**](https://github.com/Budibase/budibase/blob/HEAD/.github/CODE_OF_CONDUCT.md)を遵守していただくことお願いします。必ず読んでください。 |
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
<br /><br /> |
||||
|
|
||||
|
|
||||
|
## 🙌 Budibaseにコントリビュート |
||||
|
|
||||
|
|
||||
|
バグレポートからプルリクエストの作成まで、すべての貢献は感謝、そして歓迎されております。新しい新機能の実装やAPIの変更を計画している場合は、まずIssueを作成してください。これであなたの貴重な考えは私たちにも伝わり、無駄とはなりません。 |
||||
|
|
||||
|
### どこから始めるか混乱していますか? |
||||
|
ここはコントリビュートをはじめるための最適な場所です! [First time issues project](https://github.com/Budibase/budibase/projects/22). |
||||
|
|
||||
|
### リポジトリの構成 |
||||
|
Budibaseは、lernaによってmonorepo方式で管理されています。budibase パッケージのビルドと公開はlernaによって管理されています。Budibaseを構成するパッケージは以下の通り: |
||||
|
|
||||
|
- [packages/builder](https://github.com/Budibase/budibase/tree/HEAD/packages/builder) - budibase builder クライアントサイドのsvelteアプリケーションのコードが含まれています。 |
||||
|
|
||||
|
- [packages/client](https://github.com/Budibase/budibase/tree/HEAD/packages/client) - ブラウザ上で動作するモジュールで、JSONの定義を読み取り、そこから"生きている"Webアプリケーションを作成します。 |
||||
|
|
||||
|
- [packages/server](https://github.com/Budibase/budibase/tree/HEAD/packages/server) - budibaseのサーバーです。この Koa アプリは、builder アプリと budibase アプリの JS を提供し、データベースとファイル システムと対話するための API を提供する役割を担っています。 |
||||
|
|
||||
|
詳しくは[CONTRIBUTING.md](https://github.com/Budibase/budibase/blob/HEAD/.github/CONTRIBUTING.md)をご覧ください。 |
||||
|
|
||||
|
<br /><br /> |
||||
|
|
||||
|
|
||||
|
## 📝 ライセンス |
||||
|
|
||||
|
Budibase はオープンソースであり、[GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html)ライセンスの下に公開されています。クライアントとコンポーネントライブラリは [MPL](https://directory.fsf.org/wiki/License:MPL-2.0)で公開されています - ですから、あなたが制作したアプリケーションはどのようなライセンスでも公開することができます。 |
||||
|
|
||||
|
<br /><br /> |
||||
|
|
||||
|
## ⭐ スター数の履歴 |
||||
|
|
||||
|
[](https://starchart.cc/Budibase/budibase) |
||||
|
|
||||
|
ビルダーのアップデートの間に問題が発生する場合は[ここ](https://github.com/Budibase/budibase/blob/HEAD/.github/CONTRIBUTING.md#troubleshooting)を参考に環境をクリアにしてください。 |
||||
|
|
||||
|
<br /><br /> |
||||
|
|
||||
|
## Contributors ✨ |
||||
|
|
||||
|
すばらしい皆さまに感謝しかありません。([emoji key](https://allcontributors.org/docs/en/emoji-key)): |
||||
|
|
||||
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> |
||||
|
<!-- prettier-ignore-start --> |
||||
|
<!-- markdownlint-disable --> |
||||
|
<table> |
||||
|
<tr> |
||||
|
<td align="center"><a href="http://martinmck.com"><img src="https://avatars1.githubusercontent.com/u/11256663?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Martin McKeaveney</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=shogunpurple" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=shogunpurple" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=shogunpurple" title="Tests">⚠️</a> <a href="#infra-shogunpurple" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> |
||||
|
<td align="center"><a href="http://www.michaeldrury.co.uk/"><img src="https://avatars2.githubusercontent.com/u/4407001?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Drury</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=mike12345567" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=mike12345567" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=mike12345567" title="Tests">⚠️</a> <a href="#infra-mike12345567" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td> |
||||
|
<td align="center"><a href="https://github.com/aptkingston"><img src="https://avatars3.githubusercontent.com/u/9075550?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andrew Kingston</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=aptkingston" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=aptkingston" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=aptkingston" title="Tests">⚠️</a> <a href="#design-aptkingston" title="Design">🎨</a></td> |
||||
|
<td align="center"><a href="https://budibase.com/"><img src="https://avatars3.githubusercontent.com/u/3524181?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Shanks</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=mjashanks" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=mjashanks" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=mjashanks" title="Tests">⚠️</a></td> |
||||
|
<td align="center"><a href="https://github.com/kevmodrome"><img src="https://avatars3.githubusercontent.com/u/534488?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kevin Åberg Kultalahti</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=kevmodrome" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=kevmodrome" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=kevmodrome" title="Tests">⚠️</a></td> |
||||
|
<td align="center"><a href="https://www.budibase.com/"><img src="https://avatars2.githubusercontent.com/u/49767913?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Joe</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=joebudi" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=joebudi" title="Code">💻</a> <a href="#content-joebudi" title="Content">🖋</a> <a href="#design-joebudi" title="Design">🎨</a></td> |
||||
|
<td align="center"><a href="https://github.com/Rory-Powell"><img src="https://avatars.githubusercontent.com/u/8755148?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rory Powell</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=Rory-Powell" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=Rory-Powell" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=Rory-Powell" title="Tests">⚠️</a></td> |
||||
|
</tr> |
||||
|
<tr> |
||||
|
<td align="center"><a href="https://github.com/PClmnt"><img src="https://avatars.githubusercontent.com/u/5665926?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Peter Clement</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=PClmnt" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=PClmnt" title="Documentation">📖</a> <a href="https://github.com/Budibase/budibase/commits?author=PClmnt" title="Tests">⚠️</a></td> |
||||
|
<td align="center"><a href="https://github.com/Conor-Mack"><img src="https://avatars1.githubusercontent.com/u/36074859?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Conor_Mack</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=Conor-Mack" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=Conor-Mack" title="Tests">⚠️</a></td> |
||||
|
<td align="center"><a href="https://github.com/pngwn"><img src="https://avatars1.githubusercontent.com/u/12937446?v=4?s=100" width="100px;" alt=""/><br /><sub><b>pngwn</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=pngwn" title="Code">💻</a> <a href="https://github.com/Budibase/budibase/commits?author=pngwn" title="Tests">⚠️</a></td> |
||||
|
<td align="center"><a href="https://github.com/HugoLd"><img src="https://avatars0.githubusercontent.com/u/26521848?v=4?s=100" width="100px;" alt=""/><br /><sub><b>HugoLd</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=HugoLd" title="Code">💻</a></td> |
||||
|
<td align="center"><a href="https://github.com/victoriasloan"><img src="https://avatars.githubusercontent.com/u/9913651?v=4?s=100" width="100px;" alt=""/><br /><sub><b>victoriasloan</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=victoriasloan" title="Code">💻</a></td> |
||||
|
<td align="center"><a href="https://github.com/yashank09"><img src="https://avatars.githubusercontent.com/u/37672190?v=4?s=100" width="100px;" alt=""/><br /><sub><b>yashank09</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=yashank09" title="Code">💻</a></td> |
||||
|
<td align="center"><a href="https://github.com/SOVLOOKUP"><img src="https://avatars.githubusercontent.com/u/53158137?v=4?s=100" width="100px;" alt=""/><br /><sub><b>SOVLOOKUP</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=SOVLOOKUP" title="Code">💻</a></td> |
||||
|
<td align="center"><a href="https://github.com/seoulaja"><img src="https://avatars.githubusercontent.com/u/15101654?v=4?s=100" width="100px;" alt=""/><br /><sub><b>seoulaja</b></sub></a><br /><a href="#translation-seoulaja" title="Translation">🌍</a></td> |
||||
|
<td align="center"><a href="https://github.com/mslourens"><img src="https://avatars.githubusercontent.com/u/1907152?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Maurits Lourens</b></sub></a><br /><a href="https://github.com/Budibase/budibase/commits?author=mslourens" title="Tests">⚠️</a> <a href="https://github.com/Budibase/budibase/commits?author=mslourens" title="Code">💻</a></td> |
||||
|
</tr> |
||||
|
</table> |
||||
|
|
||||
|
<!-- markdownlint-restore --> |
||||
|
<!-- prettier-ignore-end --> |
||||
|
|
||||
|
<!-- ALL-CONTRIBUTORS-LIST:END --> |
||||
|
|
||||
|
このプロジェクトは、[all-contributors](https://github.com/all-contributors/all-contributors)仕様に準拠しています。どのような貢献でも歓迎します。 |
||||
|
|
||||
@ -0,0 +1,17 @@ |
|||||
|
const { |
||||
|
getAppDB, |
||||
|
getDevAppDB, |
||||
|
getProdAppDB, |
||||
|
getAppId, |
||||
|
updateAppId, |
||||
|
doInAppContext, |
||||
|
} = require("./src/context") |
||||
|
|
||||
|
module.exports = { |
||||
|
getAppDB, |
||||
|
getDevAppDB, |
||||
|
getProdAppDB, |
||||
|
getAppId, |
||||
|
updateAppId, |
||||
|
doInAppContext, |
||||
|
} |
||||
@ -1,5 +1,6 @@ |
|||||
module.exports = { |
module.exports = { |
||||
...require("./src/db/utils"), |
...require("./src/db/utils"), |
||||
...require("./src/db/constants"), |
...require("./src/db/constants"), |
||||
|
...require("./src/db"), |
||||
...require("./src/db/views"), |
...require("./src/db/views"), |
||||
} |
} |
||||
|
|||||
@ -1 +1 @@ |
|||||
module.exports = require("./src/tenancy/deprovision") |
module.exports = require("./src/context/deprovision") |
||||
|
|||||
@ -1,6 +1,6 @@ |
|||||
const { getGlobalUserParams, getAllApps } = require("../db/utils") |
const { getGlobalUserParams, getAllApps } = require("../db/utils") |
||||
const { getDB, getCouch } = require("../db") |
const { getDB, getCouch } = require("../db") |
||||
const { getGlobalDB } = require("./tenancy") |
const { getGlobalDB } = require("../tenancy") |
||||
const { StaticDatabases } = require("../db/constants") |
const { StaticDatabases } = require("../db/constants") |
||||
|
|
||||
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants |
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants |
||||
@ -0,0 +1,195 @@ |
|||||
|
const env = require("../environment") |
||||
|
const { Headers } = require("../../constants") |
||||
|
const cls = require("./FunctionContext") |
||||
|
const { getCouch } = require("../db") |
||||
|
const { getProdAppID, getDevelopmentAppID } = require("../db/conversions") |
||||
|
const { isEqual } = require("lodash") |
||||
|
|
||||
|
// some test cases call functions directly, need to
|
||||
|
// store an app ID to pretend there is a context
|
||||
|
let TEST_APP_ID = null |
||||
|
|
||||
|
const ContextKeys = { |
||||
|
TENANT_ID: "tenantId", |
||||
|
APP_ID: "appId", |
||||
|
// whatever the request app DB was
|
||||
|
CURRENT_DB: "currentDb", |
||||
|
// get the prod app DB from the request
|
||||
|
PROD_DB: "prodDb", |
||||
|
// get the dev app DB from the request
|
||||
|
DEV_DB: "devDb", |
||||
|
DB_OPTS: "dbOpts", |
||||
|
} |
||||
|
|
||||
|
exports.DEFAULT_TENANT_ID = "default" |
||||
|
|
||||
|
exports.isDefaultTenant = () => { |
||||
|
return exports.getTenantId() === exports.DEFAULT_TENANT_ID |
||||
|
} |
||||
|
|
||||
|
exports.isMultiTenant = () => { |
||||
|
return env.MULTI_TENANCY |
||||
|
} |
||||
|
|
||||
|
// used for automations, API endpoints should always be in context already
|
||||
|
exports.doInTenant = (tenantId, task) => { |
||||
|
return cls.run(() => { |
||||
|
// set the tenant id
|
||||
|
cls.setOnContext(ContextKeys.TENANT_ID, tenantId) |
||||
|
|
||||
|
// invoke the task
|
||||
|
return task() |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
exports.doInAppContext = (appId, task) => { |
||||
|
return cls.run(() => { |
||||
|
// set the app ID
|
||||
|
cls.setOnContext(ContextKeys.APP_ID, appId) |
||||
|
|
||||
|
// invoke the task
|
||||
|
return task() |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
exports.updateTenantId = tenantId => { |
||||
|
cls.setOnContext(ContextKeys.TENANT_ID, tenantId) |
||||
|
} |
||||
|
|
||||
|
exports.updateAppId = appId => { |
||||
|
try { |
||||
|
cls.setOnContext(ContextKeys.APP_ID, appId) |
||||
|
cls.setOnContext(ContextKeys.PROD_DB, null) |
||||
|
cls.setOnContext(ContextKeys.DEV_DB, null) |
||||
|
cls.setOnContext(ContextKeys.CURRENT_DB, null) |
||||
|
cls.setOnContext(ContextKeys.DB_OPTS, null) |
||||
|
} catch (err) { |
||||
|
if (env.isTest()) { |
||||
|
TEST_APP_ID = appId |
||||
|
} else { |
||||
|
throw err |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
exports.setTenantId = ( |
||||
|
ctx, |
||||
|
opts = { allowQs: false, allowNoTenant: false } |
||||
|
) => { |
||||
|
let tenantId |
||||
|
// exit early if not multi-tenant
|
||||
|
if (!exports.isMultiTenant()) { |
||||
|
cls.setOnContext(ContextKeys.TENANT_ID, this.DEFAULT_TENANT_ID) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
const allowQs = opts && opts.allowQs |
||||
|
const allowNoTenant = opts && opts.allowNoTenant |
||||
|
const header = ctx.request.headers[Headers.TENANT_ID] |
||||
|
const user = ctx.user || {} |
||||
|
if (allowQs) { |
||||
|
const query = ctx.request.query || {} |
||||
|
tenantId = query.tenantId |
||||
|
} |
||||
|
// override query string (if allowed) by user, or header
|
||||
|
// URL params cannot be used in a middleware, as they are
|
||||
|
// processed later in the chain
|
||||
|
tenantId = user.tenantId || header || tenantId |
||||
|
|
||||
|
// Set the tenantId from the subdomain
|
||||
|
if (!tenantId) { |
||||
|
tenantId = ctx.subdomains && ctx.subdomains[0] |
||||
|
} |
||||
|
|
||||
|
if (!tenantId && !allowNoTenant) { |
||||
|
ctx.throw(403, "Tenant id not set") |
||||
|
} |
||||
|
// check tenant ID just incase no tenant was allowed
|
||||
|
if (tenantId) { |
||||
|
cls.setOnContext(ContextKeys.TENANT_ID, tenantId) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
exports.isTenantIdSet = () => { |
||||
|
const tenantId = cls.getFromContext(ContextKeys.TENANT_ID) |
||||
|
return !!tenantId |
||||
|
} |
||||
|
|
||||
|
exports.getTenantId = () => { |
||||
|
if (!exports.isMultiTenant()) { |
||||
|
return exports.DEFAULT_TENANT_ID |
||||
|
} |
||||
|
const tenantId = cls.getFromContext(ContextKeys.TENANT_ID) |
||||
|
if (!tenantId) { |
||||
|
throw Error("Tenant id not found") |
||||
|
} |
||||
|
return tenantId |
||||
|
} |
||||
|
|
||||
|
exports.getAppId = () => { |
||||
|
const foundId = cls.getFromContext(ContextKeys.APP_ID) |
||||
|
if (!foundId && env.isTest() && TEST_APP_ID) { |
||||
|
return TEST_APP_ID |
||||
|
} else { |
||||
|
return foundId |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function getDB(key, opts) { |
||||
|
const dbOptsKey = `${key}${ContextKeys.DB_OPTS}` |
||||
|
let storedOpts = cls.getFromContext(dbOptsKey) |
||||
|
let db = cls.getFromContext(key) |
||||
|
if (db && isEqual(opts, storedOpts)) { |
||||
|
return db |
||||
|
} |
||||
|
const appId = exports.getAppId() |
||||
|
const CouchDB = getCouch() |
||||
|
let toUseAppId |
||||
|
switch (key) { |
||||
|
case ContextKeys.CURRENT_DB: |
||||
|
toUseAppId = appId |
||||
|
break |
||||
|
case ContextKeys.PROD_DB: |
||||
|
toUseAppId = getProdAppID(appId) |
||||
|
break |
||||
|
case ContextKeys.DEV_DB: |
||||
|
toUseAppId = getDevelopmentAppID(appId) |
||||
|
break |
||||
|
} |
||||
|
db = new CouchDB(toUseAppId, opts) |
||||
|
try { |
||||
|
cls.setOnContext(key, db) |
||||
|
if (opts) { |
||||
|
cls.setOnContext(dbOptsKey, opts) |
||||
|
} |
||||
|
} catch (err) { |
||||
|
if (!env.isTest()) { |
||||
|
throw err |
||||
|
} |
||||
|
} |
||||
|
return db |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Opens the app database based on whatever the request |
||||
|
* contained, dev or prod. |
||||
|
*/ |
||||
|
exports.getAppDB = opts => { |
||||
|
return getDB(ContextKeys.CURRENT_DB, opts) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* This specifically gets the prod app ID, if the request |
||||
|
* contained a development app ID, this will open the prod one. |
||||
|
*/ |
||||
|
exports.getProdAppDB = opts => { |
||||
|
return getDB(ContextKeys.PROD_DB, opts) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* This specifically gets the dev app ID, if the request |
||||
|
* contained a prod app ID, this will open the dev one. |
||||
|
*/ |
||||
|
exports.getDevAppDB = opts => { |
||||
|
return getDB(ContextKeys.DEV_DB, opts) |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
const NO_APP_ERROR = "No app provided" |
||||
|
const { APP_DEV_PREFIX, APP_PREFIX } = require("./constants") |
||||
|
|
||||
|
exports.isDevAppID = appId => { |
||||
|
if (!appId) { |
||||
|
throw NO_APP_ERROR |
||||
|
} |
||||
|
return appId.startsWith(APP_DEV_PREFIX) |
||||
|
} |
||||
|
|
||||
|
exports.isProdAppID = appId => { |
||||
|
if (!appId) { |
||||
|
throw NO_APP_ERROR |
||||
|
} |
||||
|
return appId.startsWith(APP_PREFIX) && !exports.isDevAppID(appId) |
||||
|
} |
||||
|
|
||||
|
exports.isDevApp = app => { |
||||
|
if (!app) { |
||||
|
throw NO_APP_ERROR |
||||
|
} |
||||
|
return exports.isDevAppID(app.appId) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Convert a development app ID to a deployed app ID. |
||||
|
*/ |
||||
|
exports.getProdAppID = appId => { |
||||
|
// if dev, convert it
|
||||
|
if (appId.startsWith(APP_DEV_PREFIX)) { |
||||
|
const id = appId.split(APP_DEV_PREFIX)[1] |
||||
|
return `${APP_PREFIX}${id}` |
||||
|
} |
||||
|
return appId |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Convert a deployed app ID to a development app ID. |
||||
|
*/ |
||||
|
exports.getDevelopmentAppID = appId => { |
||||
|
if (!appId.startsWith(APP_DEV_PREFIX)) { |
||||
|
const id = appId.split(APP_PREFIX)[1] |
||||
|
return `${APP_DEV_PREFIX}${id}` |
||||
|
} |
||||
|
return appId |
||||
|
} |
||||
@ -1,84 +0,0 @@ |
|||||
const env = require("../environment") |
|
||||
const { Headers } = require("../../constants") |
|
||||
const cls = require("./FunctionContext") |
|
||||
|
|
||||
exports.DEFAULT_TENANT_ID = "default" |
|
||||
|
|
||||
exports.isDefaultTenant = () => { |
|
||||
return exports.getTenantId() === exports.DEFAULT_TENANT_ID |
|
||||
} |
|
||||
|
|
||||
exports.isMultiTenant = () => { |
|
||||
return env.MULTI_TENANCY |
|
||||
} |
|
||||
|
|
||||
const TENANT_ID = "tenantId" |
|
||||
|
|
||||
// used for automations, API endpoints should always be in context already
|
|
||||
exports.doInTenant = (tenantId, task) => { |
|
||||
return cls.run(() => { |
|
||||
// set the tenant id
|
|
||||
cls.setOnContext(TENANT_ID, tenantId) |
|
||||
|
|
||||
// invoke the task
|
|
||||
return task() |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
exports.updateTenantId = tenantId => { |
|
||||
cls.setOnContext(TENANT_ID, tenantId) |
|
||||
} |
|
||||
|
|
||||
exports.setTenantId = ( |
|
||||
ctx, |
|
||||
opts = { allowQs: false, allowNoTenant: false } |
|
||||
) => { |
|
||||
let tenantId |
|
||||
// exit early if not multi-tenant
|
|
||||
if (!exports.isMultiTenant()) { |
|
||||
cls.setOnContext(TENANT_ID, this.DEFAULT_TENANT_ID) |
|
||||
return |
|
||||
} |
|
||||
|
|
||||
const allowQs = opts && opts.allowQs |
|
||||
const allowNoTenant = opts && opts.allowNoTenant |
|
||||
const header = ctx.request.headers[Headers.TENANT_ID] |
|
||||
const user = ctx.user || {} |
|
||||
if (allowQs) { |
|
||||
const query = ctx.request.query || {} |
|
||||
tenantId = query.tenantId |
|
||||
} |
|
||||
// override query string (if allowed) by user, or header
|
|
||||
// URL params cannot be used in a middleware, as they are
|
|
||||
// processed later in the chain
|
|
||||
tenantId = user.tenantId || header || tenantId |
|
||||
|
|
||||
// Set the tenantId from the subdomain
|
|
||||
if (!tenantId) { |
|
||||
tenantId = ctx.subdomains && ctx.subdomains[0] |
|
||||
} |
|
||||
|
|
||||
if (!tenantId && !allowNoTenant) { |
|
||||
ctx.throw(403, "Tenant id not set") |
|
||||
} |
|
||||
// check tenant ID just incase no tenant was allowed
|
|
||||
if (tenantId) { |
|
||||
cls.setOnContext(TENANT_ID, tenantId) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
exports.isTenantIdSet = () => { |
|
||||
const tenantId = cls.getFromContext(TENANT_ID) |
|
||||
return !!tenantId |
|
||||
} |
|
||||
|
|
||||
exports.getTenantId = () => { |
|
||||
if (!exports.isMultiTenant()) { |
|
||||
return exports.DEFAULT_TENANT_ID |
|
||||
} |
|
||||
const tenantId = cls.getFromContext(TENANT_ID) |
|
||||
if (!tenantId) { |
|
||||
throw Error("Tenant id not found") |
|
||||
} |
|
||||
return tenantId |
|
||||
} |
|
||||
@ -1,4 +1,4 @@ |
|||||
module.exports = { |
module.exports = { |
||||
...require("./context"), |
...require("../context"), |
||||
...require("./tenancy"), |
...require("./tenancy"), |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,42 @@ |
|||||
|
<script> |
||||
|
import MarkdownEditor from "../../Markdown/MarkdownEditor.svelte" |
||||
|
|
||||
|
export let value = "" |
||||
|
export let placeholder = null |
||||
|
export let disabled = false |
||||
|
export let error = null |
||||
|
export let height = null |
||||
|
export let id = null |
||||
|
export let fullScreenOffset = null |
||||
|
export let easyMDEOptions = null |
||||
|
</script> |
||||
|
|
||||
|
<div class:error> |
||||
|
<MarkdownEditor |
||||
|
{value} |
||||
|
{placeholder} |
||||
|
{height} |
||||
|
{id} |
||||
|
{fullScreenOffset} |
||||
|
{disabled} |
||||
|
{easyMDEOptions} |
||||
|
on:change |
||||
|
/> |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
.error :global(.EasyMDEContainer .editor-toolbar) { |
||||
|
border-top-color: var(--spectrum-semantic-negative-color-default); |
||||
|
border-left-color: var(--spectrum-semantic-negative-color-default); |
||||
|
border-right-color: var(--spectrum-semantic-negative-color-default); |
||||
|
} |
||||
|
.error :global(.EasyMDEContainer .CodeMirror) { |
||||
|
border-bottom-color: var(--spectrum-semantic-negative-color-default); |
||||
|
border-left-color: var(--spectrum-semantic-negative-color-default); |
||||
|
border-right-color: var(--spectrum-semantic-negative-color-default); |
||||
|
} |
||||
|
.error :global(.EasyMDEContainer .editor-preview-side) { |
||||
|
border-bottom-color: var(--spectrum-semantic-negative-color-default); |
||||
|
border-right-color: var(--spectrum-semantic-negative-color-default); |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,36 @@ |
|||||
|
<script> |
||||
|
import Field from "./Field.svelte" |
||||
|
import RichTextField from "./Core/RichTextField.svelte" |
||||
|
import { createEventDispatcher } from "svelte" |
||||
|
|
||||
|
export let value = null |
||||
|
export let label = null |
||||
|
export let labelPosition = "above" |
||||
|
export let placeholder = null |
||||
|
export let disabled = false |
||||
|
export let error = null |
||||
|
export let height = null |
||||
|
export let id = null |
||||
|
export let fullScreenOffset = null |
||||
|
export let easyMDEOptions = null |
||||
|
|
||||
|
const dispatch = createEventDispatcher() |
||||
|
const onChange = e => { |
||||
|
value = e.detail |
||||
|
dispatch("change", e.detail) |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<Field {label} {labelPosition} {error}> |
||||
|
<RichTextField |
||||
|
{error} |
||||
|
{disabled} |
||||
|
{value} |
||||
|
{placeholder} |
||||
|
{height} |
||||
|
{id} |
||||
|
{fullScreenOffset} |
||||
|
{easyMDEOptions} |
||||
|
on:change={onChange} |
||||
|
/> |
||||
|
</Field> |
||||
@ -0,0 +1,60 @@ |
|||||
|
<script> |
||||
|
import SpectrumMDE from "./SpectrumMDE.svelte" |
||||
|
import { createEventDispatcher } from "svelte" |
||||
|
|
||||
|
export let value = null |
||||
|
export let height = null |
||||
|
export let placeholder = null |
||||
|
export let id = null |
||||
|
export let fullScreenOffset = 0 |
||||
|
export let disabled = false |
||||
|
export let easyMDEOptions |
||||
|
|
||||
|
const dispatch = createEventDispatcher() |
||||
|
|
||||
|
let latestValue |
||||
|
let mde |
||||
|
|
||||
|
// Ensure the value is updated if the value prop changes outside the editor's |
||||
|
// control |
||||
|
$: checkValue(value) |
||||
|
$: mde?.codemirror.on("change", debouncedUpdate) |
||||
|
|
||||
|
const checkValue = val => { |
||||
|
if (mde && val !== latestValue) { |
||||
|
mde.value(val) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const debounce = (fn, interval) => { |
||||
|
let timeout |
||||
|
return () => { |
||||
|
clearTimeout(timeout) |
||||
|
timeout = setTimeout(fn, interval) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const update = () => { |
||||
|
latestValue = mde.value() |
||||
|
dispatch("change", latestValue) |
||||
|
} |
||||
|
|
||||
|
// Debounce the update function to avoid spamming it constantly |
||||
|
const debouncedUpdate = debounce(update, 250) |
||||
|
</script> |
||||
|
|
||||
|
{#key height} |
||||
|
<SpectrumMDE |
||||
|
bind:mde |
||||
|
scroll={true} |
||||
|
{height} |
||||
|
{id} |
||||
|
{fullScreenOffset} |
||||
|
{disabled} |
||||
|
easyMDEOptions={{ |
||||
|
initialValue: value, |
||||
|
placeholder, |
||||
|
...easyMDEOptions, |
||||
|
}} |
||||
|
/> |
||||
|
{/key} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<script> |
||||
|
import SpectrumMDE from "./SpectrumMDE.svelte" |
||||
|
|
||||
|
export let value |
||||
|
export let height |
||||
|
|
||||
|
let mde |
||||
|
|
||||
|
// Keep the value up to date |
||||
|
$: mde && mde.value(value || "") |
||||
|
$: { |
||||
|
if (mde && !mde.isPreviewActive()) { |
||||
|
mde.togglePreview() |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div class="markdown-viewer" style="height:{height};"> |
||||
|
<SpectrumMDE |
||||
|
bind:mde |
||||
|
scroll={false} |
||||
|
easyMDEOptions={{ |
||||
|
initialValue: value, |
||||
|
toolbar: false, |
||||
|
}} |
||||
|
/> |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
.markdown-viewer { |
||||
|
overflow: auto; |
||||
|
} |
||||
|
/* Remove padding, borders and background colors */ |
||||
|
.markdown-viewer :global(.editor-preview) { |
||||
|
padding: 0; |
||||
|
border: none; |
||||
|
background: transparent; |
||||
|
} |
||||
|
.markdown-viewer :global(.CodeMirror) { |
||||
|
border: none; |
||||
|
background: transparent; |
||||
|
padding: 0; |
||||
|
} |
||||
|
.markdown-viewer :global(.EasyMDEContainer) { |
||||
|
background: transparent; |
||||
|
} |
||||
|
/* Hide the actual code editor */ |
||||
|
.markdown-viewer :global(.CodeMirror-scroll) { |
||||
|
display: none; |
||||
|
} |
||||
|
/*Hide the scrollbar*/ |
||||
|
.markdown-viewer :global(.CodeMirror-vscrollbar) { |
||||
|
display: none !important; |
||||
|
} |
||||
|
/*Position relatively so we only consume whatever space we need */ |
||||
|
.markdown-viewer :global(.editor-preview-full) { |
||||
|
position: relative; |
||||
|
} |
||||
|
/* Remove margin on the first and last components to fully trim the preview */ |
||||
|
.markdown-viewer :global(.editor-preview-full > :first-child) { |
||||
|
margin-top: 0; |
||||
|
} |
||||
|
.markdown-viewer :global(.editor-preview-full > :last-child) { |
||||
|
margin-bottom: 0; |
||||
|
} |
||||
|
/* Code blocks in preview */ |
||||
|
.markdown-viewer :global(.editor-preview-full pre) { |
||||
|
background: var(--spectrum-global-color-gray-200); |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,184 @@ |
|||||
|
<script> |
||||
|
import EasyMDE from "easymde" |
||||
|
import "easymde/dist/easymde.min.css" |
||||
|
import { onMount } from "svelte" |
||||
|
|
||||
|
export let height = null |
||||
|
export let scroll = true |
||||
|
export let easyMDEOptions = null |
||||
|
export let mde = null |
||||
|
export let id = null |
||||
|
export let fullScreenOffset = null |
||||
|
export let disabled = false |
||||
|
|
||||
|
let element |
||||
|
|
||||
|
onMount(() => { |
||||
|
height = height || "200px" |
||||
|
mde = new EasyMDE({ |
||||
|
element, |
||||
|
spellChecker: false, |
||||
|
status: false, |
||||
|
unorderedListStyle: "-", |
||||
|
maxHeight: scroll ? height : undefined, |
||||
|
minHeight: scroll ? undefined : height, |
||||
|
...easyMDEOptions, |
||||
|
}) |
||||
|
|
||||
|
// Revert the editor when we unmount |
||||
|
return () => { |
||||
|
mde.toTextArea() |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
$: styleString = getStyleString(fullScreenOffset) |
||||
|
|
||||
|
const getStyleString = offset => { |
||||
|
let string = "" |
||||
|
string += `--fullscreen-offset-x:${offset?.x || "0px"};` |
||||
|
string += `--fullscreen-offset-y:${offset?.y || "0px"};` |
||||
|
return string |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div class:disabled style={styleString}> |
||||
|
<textarea disabled {id} bind:this={element} /> |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
/* Disabled styles */ |
||||
|
.disabled :global(textarea) { |
||||
|
display: none; |
||||
|
} |
||||
|
.disabled :global(.CodeMirror-cursor) { |
||||
|
display: none; |
||||
|
} |
||||
|
.disabled :global(.EasyMDEContainer) { |
||||
|
pointer-events: none; |
||||
|
} |
||||
|
.disabled :global(.editor-toolbar button i) { |
||||
|
color: var(--spectrum-global-color-gray-400); |
||||
|
} |
||||
|
.disabled :global(.CodeMirror) { |
||||
|
color: var(--spectrum-global-color-gray-600); |
||||
|
} |
||||
|
|
||||
|
/* Toolbar container */ |
||||
|
:global(.EasyMDEContainer .editor-toolbar) { |
||||
|
background: var(--spectrum-global-color-gray-50); |
||||
|
border-top: 1px solid var(--spectrum-alias-border-color); |
||||
|
border-left: 1px solid var(--spectrum-alias-border-color); |
||||
|
border-right: 1px solid var(--spectrum-alias-border-color); |
||||
|
} |
||||
|
/* Main code mirror instance and default color */ |
||||
|
:global(.EasyMDEContainer .CodeMirror) { |
||||
|
border: 1px solid var(--spectrum-alias-border-color); |
||||
|
background: var(--spectrum-global-color-gray-50); |
||||
|
color: var(--spectrum-alias-text-color); |
||||
|
} |
||||
|
/* Toolbar button active state */ |
||||
|
:global(.EasyMDEContainer .editor-toolbar button.active) { |
||||
|
background: var(--spectrum-global-color-gray-200); |
||||
|
border-color: var(--spectrum-global-color-gray-400); |
||||
|
} |
||||
|
/* Toolbar button hover state */ |
||||
|
:global(.EasyMDEContainer .editor-toolbar button:hover) { |
||||
|
background: var(--spectrum-global-color-gray-200); |
||||
|
border-color: var(--spectrum-global-color-gray-400); |
||||
|
} |
||||
|
/* Toolbar button color */ |
||||
|
:global(.EasyMDEContainer .editor-toolbar button i) { |
||||
|
color: var(--spectrum-global-color-gray-800); |
||||
|
} |
||||
|
/* Separator between toolbar buttons*/ |
||||
|
:global(.EasyMDEContainer .editor-toolbar i.separator) { |
||||
|
border-color: var(--spectrum-global-color-gray-300); |
||||
|
} |
||||
|
/* Cursor */ |
||||
|
:global(.EasyMDEContainer .CodeMirror-cursor) { |
||||
|
border-color: var(--spectrum-alias-text-color); |
||||
|
} |
||||
|
/* Text selections */ |
||||
|
:global(.EasyMDEContainer .CodeMirror-selectedtext) { |
||||
|
background: var(--spectrum-global-color-gray-400) !important; |
||||
|
} |
||||
|
/* Background of lines containing selected text */ |
||||
|
:global(.EasyMDEContainer .CodeMirror-selected) { |
||||
|
background: var(--spectrum-global-color-gray-400) !important; |
||||
|
} |
||||
|
/* Color of text for images and links */ |
||||
|
:global(.EasyMDEContainer .cm-s-easymde .cm-link) { |
||||
|
color: var(--spectrum-global-color-gray-600); |
||||
|
} |
||||
|
/* Color of URL for images and links */ |
||||
|
:global(.EasyMDEContainer .cm-s-easymde .cm-url) { |
||||
|
color: var(--spectrum-global-color-gray-500); |
||||
|
} |
||||
|
/* Full preview window */ |
||||
|
:global(.EasyMDEContainer .editor-preview) { |
||||
|
background: var(--spectrum-global-color-gray-50); |
||||
|
} |
||||
|
/* Side by side preview window */ |
||||
|
:global(.EasyMDEContainer .editor-preview) { |
||||
|
border: 1px solid var(--spectrum-alias-border-color); |
||||
|
} |
||||
|
/* Code blocks in editor */ |
||||
|
:global(.EasyMDEContainer .cm-s-easymde .cm-comment) { |
||||
|
background: var(--spectrum-global-color-gray-100); |
||||
|
} |
||||
|
/* Code blocks in preview */ |
||||
|
:global(.EasyMDEContainer pre) { |
||||
|
background: var(--spectrum-global-color-gray-100); |
||||
|
padding: 4px; |
||||
|
border-radius: 4px; |
||||
|
} |
||||
|
:global(.EasyMDEContainer code) { |
||||
|
color: #e83e8c; |
||||
|
} |
||||
|
:global(.EasyMDEContainer pre code) { |
||||
|
color: var(--spectrum-alias-text-color); |
||||
|
} |
||||
|
/* Block quotes */ |
||||
|
:global(.EasyMDEContainer blockquote) { |
||||
|
border-left: 4px solid var(--spectrum-global-color-gray-400); |
||||
|
color: var(--spectrum-global-color-gray-700); |
||||
|
margin-left: 0; |
||||
|
padding-left: 20px; |
||||
|
} |
||||
|
/* HR's */ |
||||
|
:global(.EasyMDEContainer hr) { |
||||
|
background-color: var(--spectrum-global-color-gray-300); |
||||
|
border: none; |
||||
|
height: 2px; |
||||
|
} |
||||
|
/* Tables */ |
||||
|
:global(.EasyMDEContainer td, .EasyMDEContainer th) { |
||||
|
border-color: var(--spectrum-alias-border-color) !important; |
||||
|
} |
||||
|
/* Links */ |
||||
|
:global(.EasyMDEContainer a) { |
||||
|
color: var(--primaryColor); |
||||
|
} |
||||
|
:global(.EasyMDEContainer a:hover) { |
||||
|
color: var(--primaryColorHover); |
||||
|
} |
||||
|
/* Allow full screen offset */ |
||||
|
:global(.EasyMDEContainer .editor-toolbar.fullscreen) { |
||||
|
left: var(--fullscreen-offset-x); |
||||
|
top: var(--fullscreen-offset-y); |
||||
|
} |
||||
|
:global(.EasyMDEContainer .CodeMirror-fullscreen) { |
||||
|
left: var(--fullscreen-offset-x); |
||||
|
top: calc(50px + var(--fullscreen-offset-y)); |
||||
|
} |
||||
|
|
||||
|
:global(.EasyMDEContainer .CodeMirror-fullscreen.CodeMirror-sided) { |
||||
|
width: calc((100% - var(--fullscreen-offset-x)) / 2) !important; |
||||
|
} |
||||
|
|
||||
|
:global(.EasyMDEContainer .editor-preview-side) { |
||||
|
left: calc(50% + (var(--fullscreen-offset-x) / 2)); |
||||
|
top: calc(50px + var(--fullscreen-offset-y)); |
||||
|
width: calc((100% - var(--fullscreen-offset-x)) / 2) !important; |
||||
|
} |
||||
|
</style> |
||||
@ -1,11 +1,45 @@ |
|||||
export const generateID = () => { |
/** |
||||
const rand = Math.random().toString(32).substring(2) |
* Generates a DOM safe UUID. |
||||
|
* Starting with a letter is important to make it DOM safe. |
||||
|
* @return {string} a random DOM safe UUID |
||||
|
*/ |
||||
|
export function uuid() { |
||||
|
return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, c => { |
||||
|
const r = (Math.random() * 16) | 0 |
||||
|
const v = c === "x" ? r : (r & 0x3) | 0x8 |
||||
|
return v.toString(16) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
// Starts with a letter so that its a valid DOM ID
|
/** |
||||
return `A${rand}` |
* Capitalises a string |
||||
|
* @param string the string to capitalise |
||||
|
* @return {string} the capitalised string |
||||
|
*/ |
||||
|
export const capitalise = string => { |
||||
|
if (!string) { |
||||
|
return string |
||||
|
} |
||||
|
return string.substring(0, 1).toUpperCase() + string.substring(1) |
||||
} |
} |
||||
|
|
||||
export const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1) |
/** |
||||
|
* Computes a short hash of a string |
||||
|
* @param string the string to compute a hash of |
||||
|
* @return {string} the hash string |
||||
|
*/ |
||||
|
export const hashString = string => { |
||||
|
if (!string) { |
||||
|
return "0" |
||||
|
} |
||||
|
let hash = 0 |
||||
|
for (let i = 0; i < string.length; i++) { |
||||
|
let char = string.charCodeAt(i) |
||||
|
hash = (hash << 5) - hash + char |
||||
|
hash = hash & hash // Convert to 32bit integer
|
||||
|
} |
||||
|
return hash.toString() |
||||
|
} |
||||
|
|
||||
/** |
/** |
||||
* Gets a key within an object. The key supports dot syntax for retrieving deep |
* Gets a key within an object. The key supports dot syntax for retrieving deep |
||||
@ -0,0 +1,4 @@ |
|||||
|
// @ts-ignore
|
||||
|
import { run } from "../setup" |
||||
|
|
||||
|
run("../../server/src/index", "../../worker/src/index") |
||||
@ -0,0 +1,48 @@ |
|||||
|
import { |
||||
|
createAPIClient, |
||||
|
CookieUtils, |
||||
|
Constants, |
||||
|
} from "@budibase/frontend-core" |
||||
|
import { store } from "./builderStore" |
||||
|
import { get } from "svelte/store" |
||||
|
import { auth } from "./stores/portal" |
||||
|
|
||||
|
export const API = createAPIClient({ |
||||
|
attachHeaders: headers => { |
||||
|
// Attach app ID header from store
|
||||
|
headers["x-budibase-app-id"] = get(store).appId |
||||
|
|
||||
|
// Add csrf token if authenticated
|
||||
|
const user = get(auth).user |
||||
|
if (user?.csrfToken) { |
||||
|
headers["x-csrf-token"] = user.csrfToken |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
onError: error => { |
||||
|
const { url, message, status, method, handled } = error || {} |
||||
|
|
||||
|
// Log all API errors to Sentry
|
||||
|
// analytics.captureException(error)
|
||||
|
|
||||
|
// Log any errors that we haven't manually handled
|
||||
|
if (!handled) { |
||||
|
console.error("Unhandled error from API client", error) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// Log all errors to console
|
||||
|
console.warn(`[Builder] HTTP ${status} on ${method}:${url}\n\t${message}`) |
||||
|
|
||||
|
// Logout on 403's
|
||||
|
if (status === 403) { |
||||
|
// Remove cookies
|
||||
|
CookieUtils.removeCookie(Constants.Cookies.Auth) |
||||
|
|
||||
|
// Reload after removing cookie, go to login
|
||||
|
if (!url.includes("self") && !url.includes("login")) { |
||||
|
location.reload() |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
}) |
||||
@ -1,49 +0,0 @@ |
|||||
import { store } from "./index" |
|
||||
import { get as svelteGet } from "svelte/store" |
|
||||
import { removeCookie, Cookies } from "./cookies" |
|
||||
import { auth } from "stores/portal" |
|
||||
|
|
||||
const apiCall = |
|
||||
method => |
|
||||
async (url, body, headers = { "Content-Type": "application/json" }) => { |
|
||||
headers["x-budibase-app-id"] = svelteGet(store).appId |
|
||||
headers["x-budibase-api-version"] = "1" |
|
||||
|
|
||||
// add csrf token if authenticated
|
|
||||
const user = svelteGet(auth).user |
|
||||
if (user && user.csrfToken) { |
|
||||
headers["x-csrf-token"] = user.csrfToken |
|
||||
} |
|
||||
|
|
||||
const json = headers["Content-Type"] === "application/json" |
|
||||
const resp = await fetch(url, { |
|
||||
method: method, |
|
||||
body: json ? JSON.stringify(body) : body, |
|
||||
headers, |
|
||||
}) |
|
||||
if (resp.status === 403) { |
|
||||
if (url.includes("/api/templates")) { |
|
||||
return { json: () => [] } |
|
||||
} |
|
||||
removeCookie(Cookies.Auth) |
|
||||
// reload after removing cookie, go to login
|
|
||||
if (!url.includes("self") && !url.includes("login")) { |
|
||||
location.reload() |
|
||||
} |
|
||||
} |
|
||||
return resp |
|
||||
} |
|
||||
|
|
||||
export const post = apiCall("POST") |
|
||||
export const get = apiCall("GET") |
|
||||
export const patch = apiCall("PATCH") |
|
||||
export const del = apiCall("DELETE") |
|
||||
export const put = apiCall("PUT") |
|
||||
|
|
||||
export default { |
|
||||
post: apiCall("POST"), |
|
||||
get: apiCall("GET"), |
|
||||
patch: apiCall("PATCH"), |
|
||||
delete: apiCall("DELETE"), |
|
||||
put: apiCall("PUT"), |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
import { get } from "builderStore/api" |
|
||||
|
|
||||
/** |
|
||||
* Fetches the definitions for component library components. This includes |
|
||||
* their props and other metadata from components.json. |
|
||||
* @param {string} appId - ID of the currently running app |
|
||||
*/ |
|
||||
export const fetchComponentLibDefinitions = async appId => { |
|
||||
const LIB_DEFINITION_URL = `/api/${appId}/components/definitions` |
|
||||
try { |
|
||||
const libDefinitionResponse = await get(LIB_DEFINITION_URL) |
|
||||
return await libDefinitionResponse.json() |
|
||||
} catch (err) { |
|
||||
console.error(`Error fetching component definitions for ${appId}`, err) |
|
||||
} |
|
||||
} |
|
||||
@ -1,23 +0,0 @@ |
|||||
import { writable } from "svelte/store" |
|
||||
import { generate } from "shortid" |
|
||||
|
|
||||
export const notificationStore = writable({ |
|
||||
notifications: [], |
|
||||
}) |
|
||||
|
|
||||
export function send(message, type = "default") { |
|
||||
notificationStore.update(state => { |
|
||||
state.notifications = [ |
|
||||
...state.notifications, |
|
||||
{ id: generate(), type, message }, |
|
||||
] |
|
||||
return state |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
export const notifier = { |
|
||||
danger: msg => send(msg, "danger"), |
|
||||
warning: msg => send(msg, "warning"), |
|
||||
info: msg => send(msg, "info"), |
|
||||
success: msg => send(msg, "success"), |
|
||||
} |
|
||||
@ -1,9 +0,0 @@ |
|||||
export function uuid() { |
|
||||
// always want to make this start with a letter, as this makes it
|
|
||||
// easier to use with template string bindings in the client
|
|
||||
return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, c => { |
|
||||
const r = (Math.random() * 16) | 0, |
|
||||
v = c == "x" ? r : (r & 0x3) | 0x8 |
|
||||
return v.toString(16) |
|
||||
}) |
|
||||
} |
|
||||
@ -1,34 +0,0 @@ |
|||||
import api from "builderStore/api" |
|
||||
|
|
||||
export async function createUser(user) { |
|
||||
const CREATE_USER_URL = `/api/users/metadata` |
|
||||
const response = await api.post(CREATE_USER_URL, user) |
|
||||
return await response.json() |
|
||||
} |
|
||||
|
|
||||
export async function saveRow(row, tableId) { |
|
||||
const SAVE_ROW_URL = `/api/${tableId}/rows` |
|
||||
const response = await api.post(SAVE_ROW_URL, row) |
|
||||
|
|
||||
return await response.json() |
|
||||
} |
|
||||
|
|
||||
export async function deleteRow(row) { |
|
||||
const DELETE_ROWS_URL = `/api/${row.tableId}/rows` |
|
||||
return api.delete(DELETE_ROWS_URL, { |
|
||||
_id: row._id, |
|
||||
_rev: row._rev, |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
export async function fetchDataForTable(tableId) { |
|
||||
const FETCH_ROWS_URL = `/api/${tableId}/rows` |
|
||||
|
|
||||
const response = await api.get(FETCH_ROWS_URL) |
|
||||
const json = await response.json() |
|
||||
|
|
||||
if (response.status !== 200) { |
|
||||
throw new Error(json.message) |
|
||||
} |
|
||||
return json |
|
||||
} |
|
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue