emdash-niaga-commerce 0.0.0-stage → 0.1.0
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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.id.md +269 -0
- package/README.md +268 -2
- package/bin/niaga.mjs +47 -0
- package/dist/admin/fees.d.ts +2 -0
- package/dist/admin/fees.d.ts.map +1 -0
- package/dist/admin/fees.js +87 -0
- package/dist/admin/fees.js.map +1 -0
- package/dist/admin/index.d.ts +30 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +31 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/orders.d.ts +5 -0
- package/dist/admin/orders.d.ts.map +1 -0
- package/dist/admin/orders.js +123 -0
- package/dist/admin/orders.js.map +1 -0
- package/dist/admin/products.d.ts +2 -0
- package/dist/admin/products.d.ts.map +1 -0
- package/dist/admin/products.js +187 -0
- package/dist/admin/products.js.map +1 -0
- package/dist/admin/reports.d.ts +8 -0
- package/dist/admin/reports.d.ts.map +1 -0
- package/dist/admin/reports.js +41 -0
- package/dist/admin/reports.js.map +1 -0
- package/dist/admin/returns.d.ts +2 -0
- package/dist/admin/returns.d.ts.map +1 -0
- package/dist/admin/returns.js +32 -0
- package/dist/admin/returns.js.map +1 -0
- package/dist/admin/settings.d.ts +2 -0
- package/dist/admin/settings.d.ts.map +1 -0
- package/dist/admin/settings.js +82 -0
- package/dist/admin/settings.js.map +1 -0
- package/dist/admin/ui.d.ts +139 -0
- package/dist/admin/ui.d.ts.map +1 -0
- package/dist/admin/ui.js +368 -0
- package/dist/admin/ui.js.map +1 -0
- package/dist/admin/vouchers.d.ts +2 -0
- package/dist/admin/vouchers.d.ts.map +1 -0
- package/dist/admin/vouchers.js +51 -0
- package/dist/admin/vouchers.js.map +1 -0
- package/dist/descriptor.d.ts +27 -0
- package/dist/descriptor.d.ts.map +1 -0
- package/dist/descriptor.js +45 -0
- package/dist/descriptor.js.map +1 -0
- package/dist/i18n/admin-en.d.ts +329 -0
- package/dist/i18n/admin-en.d.ts.map +1 -0
- package/dist/i18n/admin-en.js +328 -0
- package/dist/i18n/admin-en.js.map +1 -0
- package/dist/i18n/admin-id.d.ts +4 -0
- package/dist/i18n/admin-id.d.ts.map +1 -0
- package/dist/i18n/admin-id.js +327 -0
- package/dist/i18n/admin-id.js.map +1 -0
- package/dist/i18n/en.d.ts +385 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +385 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/id.d.ts +4 -0
- package/dist/i18n/id.d.ts.map +1 -0
- package/dist/i18n/id.js +384 -0
- package/dist/i18n/id.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/mock.d.ts +5 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/mock.js +34 -0
- package/dist/mock.js.map +1 -0
- package/dist/plugin.d.ts +8 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +402 -0
- package/dist/plugin.js.map +1 -0
- package/dist/routes/storefront.d.ts +21 -0
- package/dist/routes/storefront.d.ts.map +1 -0
- package/dist/routes/storefront.js +233 -0
- package/dist/routes/storefront.js.map +1 -0
- package/dist/routes/webhook.d.ts +8 -0
- package/dist/routes/webhook.d.ts.map +1 -0
- package/dist/routes/webhook.js +14 -0
- package/dist/routes/webhook.js.map +1 -0
- package/dist/runtime/host.d.ts +68 -0
- package/dist/runtime/host.d.ts.map +1 -0
- package/dist/runtime/host.js +165 -0
- package/dist/runtime/host.js.map +1 -0
- package/dist/runtime/maintenance.d.ts +37 -0
- package/dist/runtime/maintenance.d.ts.map +1 -0
- package/dist/runtime/maintenance.js +44 -0
- package/dist/runtime/maintenance.js.map +1 -0
- package/dist/server/accounts.d.ts +135 -0
- package/dist/server/accounts.d.ts.map +1 -0
- package/dist/server/accounts.js +225 -0
- package/dist/server/accounts.js.map +1 -0
- package/dist/server/admin-queue.d.ts +180 -0
- package/dist/server/admin-queue.d.ts.map +1 -0
- package/dist/server/admin-queue.js +210 -0
- package/dist/server/admin-queue.js.map +1 -0
- package/dist/server/auth.d.ts +22 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/auth.js +130 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/cart.d.ts +70 -0
- package/dist/server/cart.d.ts.map +1 -0
- package/dist/server/cart.js +91 -0
- package/dist/server/cart.js.map +1 -0
- package/dist/server/catalog.d.ts +259 -0
- package/dist/server/catalog.d.ts.map +1 -0
- package/dist/server/catalog.js +328 -0
- package/dist/server/catalog.js.map +1 -0
- package/dist/server/checkout.d.ts +132 -0
- package/dist/server/checkout.d.ts.map +1 -0
- package/dist/server/checkout.js +306 -0
- package/dist/server/checkout.js.map +1 -0
- package/dist/server/db.d.ts +35 -0
- package/dist/server/db.d.ts.map +1 -0
- package/dist/server/db.js +25 -0
- package/dist/server/db.js.map +1 -0
- package/dist/server/documents.d.ts +25 -0
- package/dist/server/documents.d.ts.map +1 -0
- package/dist/server/documents.js +99 -0
- package/dist/server/documents.js.map +1 -0
- package/dist/server/events.d.ts +73 -0
- package/dist/server/events.d.ts.map +1 -0
- package/dist/server/events.js +109 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/fees/index.d.ts +7 -0
- package/dist/server/fees/index.d.ts.map +1 -0
- package/dist/server/fees/index.js +7 -0
- package/dist/server/fees/index.js.map +1 -0
- package/dist/server/fees/invoices.d.ts +110 -0
- package/dist/server/fees/invoices.d.ts.map +1 -0
- package/dist/server/fees/invoices.js +141 -0
- package/dist/server/fees/invoices.js.map +1 -0
- package/dist/server/fees/math.d.ts +142 -0
- package/dist/server/fees/math.d.ts.map +1 -0
- package/dist/server/fees/math.js +167 -0
- package/dist/server/fees/math.js.map +1 -0
- package/dist/server/fees/pdf.d.ts +8 -0
- package/dist/server/fees/pdf.d.ts.map +1 -0
- package/dist/server/fees/pdf.js +215 -0
- package/dist/server/fees/pdf.js.map +1 -0
- package/dist/server/fees/store.d.ts +128 -0
- package/dist/server/fees/store.d.ts.map +1 -0
- package/dist/server/fees/store.js +308 -0
- package/dist/server/fees/store.js.map +1 -0
- package/dist/server/fees/sync.d.ts +24 -0
- package/dist/server/fees/sync.d.ts.map +1 -0
- package/dist/server/fees/sync.js +45 -0
- package/dist/server/fees/sync.js.map +1 -0
- package/dist/server/fulfillment.d.ts +173 -0
- package/dist/server/fulfillment.d.ts.map +1 -0
- package/dist/server/fulfillment.js +469 -0
- package/dist/server/fulfillment.js.map +1 -0
- package/dist/server/google.d.ts +35 -0
- package/dist/server/google.d.ts.map +1 -0
- package/dist/server/google.js +96 -0
- package/dist/server/google.js.map +1 -0
- package/dist/server/http.d.ts +26 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +73 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/i18n.d.ts +44 -0
- package/dist/server/i18n.d.ts.map +1 -0
- package/dist/server/i18n.js +79 -0
- package/dist/server/i18n.js.map +1 -0
- package/dist/server/index.d.ts +35 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +35 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/migrate.d.ts +15 -0
- package/dist/server/migrate.d.ts.map +1 -0
- package/dist/server/migrate.js +49 -0
- package/dist/server/migrate.js.map +1 -0
- package/dist/server/migrations.generated.d.ts +7 -0
- package/dist/server/migrations.generated.d.ts.map +1 -0
- package/dist/server/migrations.generated.js +95 -0
- package/dist/server/migrations.generated.js.map +1 -0
- package/dist/server/notifications.d.ts +52 -0
- package/dist/server/notifications.d.ts.map +1 -0
- package/dist/server/notifications.js +168 -0
- package/dist/server/notifications.js.map +1 -0
- package/dist/server/orders.d.ts +209 -0
- package/dist/server/orders.d.ts.map +1 -0
- package/dist/server/orders.js +269 -0
- package/dist/server/orders.js.map +1 -0
- package/dist/server/program.d.ts +81 -0
- package/dist/server/program.d.ts.map +1 -0
- package/dist/server/program.js +112 -0
- package/dist/server/program.js.map +1 -0
- package/dist/server/providers.d.ts +55 -0
- package/dist/server/providers.d.ts.map +1 -0
- package/dist/server/providers.js +84 -0
- package/dist/server/providers.js.map +1 -0
- package/dist/server/reports.d.ts +195 -0
- package/dist/server/reports.d.ts.map +1 -0
- package/dist/server/reports.js +248 -0
- package/dist/server/reports.js.map +1 -0
- package/dist/server/roles.d.ts +46 -0
- package/dist/server/roles.d.ts.map +1 -0
- package/dist/server/roles.js +75 -0
- package/dist/server/roles.js.map +1 -0
- package/dist/server/settings.d.ts +92 -0
- package/dist/server/settings.d.ts.map +1 -0
- package/dist/server/settings.js +113 -0
- package/dist/server/settings.js.map +1 -0
- package/dist/server/stock.d.ts +137 -0
- package/dist/server/stock.d.ts.map +1 -0
- package/dist/server/stock.js +292 -0
- package/dist/server/stock.js.map +1 -0
- package/dist/server/storefront.d.ts +147 -0
- package/dist/server/storefront.d.ts.map +1 -0
- package/dist/server/storefront.js +127 -0
- package/dist/server/storefront.js.map +1 -0
- package/dist/server/text.d.ts +9 -0
- package/dist/server/text.d.ts.map +1 -0
- package/dist/server/text.js +32 -0
- package/dist/server/text.js.map +1 -0
- package/dist/server/time.d.ts +35 -0
- package/dist/server/time.d.ts.map +1 -0
- package/dist/server/time.js +93 -0
- package/dist/server/time.js.map +1 -0
- package/dist/server/util.d.ts +37 -0
- package/dist/server/util.d.ts.map +1 -0
- package/dist/server/util.js +115 -0
- package/dist/server/util.js.map +1 -0
- package/dist/server/vouchers.d.ts +159 -0
- package/dist/server/vouchers.d.ts.map +1 -0
- package/dist/server/vouchers.js +220 -0
- package/dist/server/vouchers.js.map +1 -0
- package/dist/server/webhooks.d.ts +45 -0
- package/dist/server/webhooks.d.ts.map +1 -0
- package/dist/server/webhooks.js +164 -0
- package/dist/server/webhooks.js.map +1 -0
- package/dist/testing/d1.d.ts +14 -0
- package/dist/testing/d1.d.ts.map +1 -0
- package/dist/testing/d1.js +70 -0
- package/dist/testing/d1.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/migrations/0001_core.sql +604 -0
- package/migrations/0002_fees.sql +87 -0
- package/package.json +114 -5
- package/src/admin/fees.tsx +394 -0
- package/src/admin/index.tsx +34 -0
- package/src/admin/orders.tsx +625 -0
- package/src/admin/products.tsx +567 -0
- package/src/admin/reports.tsx +245 -0
- package/src/admin/returns.tsx +138 -0
- package/src/admin/settings.tsx +387 -0
- package/src/admin/ui.tsx +484 -0
- package/src/admin/vouchers.tsx +214 -0
- package/src/descriptor.ts +60 -0
- package/src/i18n/admin-en.ts +340 -0
- package/src/i18n/admin-id.ts +340 -0
- package/src/i18n/en.ts +404 -0
- package/src/i18n/id.ts +406 -0
- package/src/index.ts +42 -0
- package/src/mock.ts +36 -0
- package/src/plugin.ts +452 -0
- package/src/routes/storefront.ts +249 -0
- package/src/routes/webhook.ts +23 -0
- package/src/runtime/cloudflare-workers.d.ts +5 -0
- package/src/runtime/host.ts +205 -0
- package/src/runtime/maintenance.ts +47 -0
- package/src/server/accounts.ts +367 -0
- package/src/server/admin-queue.ts +280 -0
- package/src/server/auth.ts +143 -0
- package/src/server/cart.ts +119 -0
- package/src/server/catalog.ts +661 -0
- package/src/server/checkout.ts +510 -0
- package/src/server/db.ts +66 -0
- package/src/server/documents.ts +102 -0
- package/src/server/events.ts +173 -0
- package/src/server/fees/index.ts +6 -0
- package/src/server/fees/invoices.ts +247 -0
- package/src/server/fees/math.ts +305 -0
- package/src/server/fees/pdf.ts +215 -0
- package/src/server/fees/store.ts +471 -0
- package/src/server/fees/sync.ts +69 -0
- package/src/server/fulfillment.ts +671 -0
- package/src/server/google.ts +101 -0
- package/src/server/http.ts +68 -0
- package/src/server/i18n.ts +88 -0
- package/src/server/index.ts +34 -0
- package/src/server/migrate.ts +55 -0
- package/src/server/migrations.generated.ts +100 -0
- package/src/server/notifications.ts +207 -0
- package/src/server/orders.ts +469 -0
- package/src/server/program.ts +139 -0
- package/src/server/providers.ts +115 -0
- package/src/server/reports.ts +413 -0
- package/src/server/roles.ts +94 -0
- package/src/server/settings.ts +162 -0
- package/src/server/stock.ts +440 -0
- package/src/server/storefront.ts +143 -0
- package/src/server/text.ts +34 -0
- package/src/server/time.ts +116 -0
- package/src/server/util.ts +128 -0
- package/src/server/vouchers.ts +329 -0
- package/src/server/webhooks.ts +191 -0
- package/src/testing/d1.ts +69 -0
- package/src/testing/index.ts +5 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
First version of the store, ported from FaRaQueen's shop and rebuilt as an EmDash plugin.
|
|
6
|
+
|
|
7
|
+
- D1 schema (`niaga_` tables) with migrations applied on first request or by `niaga migrate`.
|
|
8
|
+
- Catalogue, variant sheet that saves stock as a change from what the page showed, option axes, media from the EmDash
|
|
9
|
+
library, `importCatalog()`.
|
|
10
|
+
- Cart and checkout with stock reserved in the order's D1 batch, reservation expiry, vouchers with slot-based limits,
|
|
11
|
+
free shipping programme, Turnstile.
|
|
12
|
+
- Orders, work queue, shipments (duplicate carrier reference means "check the dashboard", never a second booking),
|
|
13
|
+
tracking, hand-over, returns and failed deliveries with refunds through the gateway or by hand.
|
|
14
|
+
- Events outbox with per-subscriber cursors, retries and parking; email notifications; document source for print
|
|
15
|
+
plugins.
|
|
16
|
+
- Buyer accounts with Google sign-in (optional).
|
|
17
|
+
- Commerce roles on top of EmDash's login: staff, owner, super admin.
|
|
18
|
+
- Sales reports with CSV; operator fee module with frozen rates, statements, PDF and CSV (optional).
|
|
19
|
+
- Admin pages in English and Indonesian, built for 390 px first.
|
|
20
|
+
- `niagaStorefront()` with the storefront API and `/api/webhooks/<provider>`; `niagaMockProviders()` for local stores.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bagus Kurnianto Labamu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.id.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# emdash-niaga-commerce
|
|
2
|
+
|
|
3
|
+
Toko online untuk situs [EmDash](https://github.com/emdash-cms/emdash), dibuat untuk penjual di Indonesia: produk
|
|
4
|
+
dengan lembar varian ala Shopee, stok yang tidak pernah terjual dua kali, keranjang dan checkout, antrean kerja pesanan
|
|
5
|
+
untuk packing dari HP, retur dan paket gagal kirim, voucher, akun pembeli, notifikasi email, laporan penjualan, dan
|
|
6
|
+
modul biaya operator (opsional). Pembayaran, pengiriman, dan cetak label datang dari plugin terpisah yang mengikuti
|
|
7
|
+
[emdash-niaga-commerce-contracts](https://github.com/baguskto/emdash-niaga-commerce/tree/main/packages/contracts), jadi toko bisa mengganti Mayar dengan gateway lain atau Biteship dengan
|
|
8
|
+
kurir lain tanpa mengubah tokonya.
|
|
9
|
+
|
|
10
|
+
English: [README.md](README.md).
|
|
11
|
+
|
|
12
|
+
**Status: 0.1, masih dikembangkan.** Sudah berjalan dari ujung ke ujung (lihat `examples/basic-store`) dan sudah diuji,
|
|
13
|
+
tetapi belum ada di npm dan belum dipakai toko produksi.
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## Fiturnya
|
|
18
|
+
|
|
19
|
+
- **Katalog**: produk, sampai dua jenis pilihan (warna, ukuran), lembar varian dengan isi-semua dan tempel satu kolom
|
|
20
|
+
dari spreadsheet, foto dan video dari pustaka media EmDash, kategori, nama dalam Bahasa Indonesia dan Inggris,
|
|
21
|
+
pencarian, dan `importCatalog()` untuk katalog JSON (ekspor Shopee bisa dipetakan ke sini).
|
|
22
|
+
- **Stok**: setiap unit dikunci saat pembeli checkout, dalam batch D1 yang sama dengan pesanannya. Constraint database
|
|
23
|
+
(`reserved <= stock`) menolak unit terakhir yang dipesan dua kali, jadi dua pembeli tidak mungkin membayar satu
|
|
24
|
+
barang. Pesanan yang tidak dibayar melepas stoknya saat batas waktu bayar lewat. Setiap perubahan tercatat di log stok.
|
|
25
|
+
- **Checkout**: checkout tamu dengan nomor WhatsApp, ongkir langsung dari plugin pengiriman, voucher, gratis ongkir dari
|
|
26
|
+
belanja minimum, Cloudflare Turnstile, dan halaman bayar dari plugin pembayaran.
|
|
27
|
+
- **Pesanan**: antrean kerja sesuai urutan kerja: pesan kurir, cetak label, serahkan ke kurir. Aksi massal, ubah alamat
|
|
28
|
+
sebelum kurir dipesan, batalkan pesanan yang belum dibayar (tagihannya ditutup di gateway), cek ulang pembayaran.
|
|
29
|
+
- **Retur dan gagal kirim**: buka kasus, kembalikan barang ke stok, tutup dengan kirim ulang, refund, tukar, saldo toko,
|
|
30
|
+
atau tanpa tindakan.
|
|
31
|
+
- **Voucher**: batch kode kartu sekali pakai atau satu kode kampanye, potongan persen, nominal, atau ongkir, belanja
|
|
32
|
+
minimum, khusus pesanan pertama, batas per pembeli dan kuota, dengan CSV kode untuk dicetak.
|
|
33
|
+
- **Akun pembeli** (opsional): masuk dengan Google, riwayat pesanan, dan alamat tersimpan. Tamu tidak perlu akun.
|
|
34
|
+
- **Event**: setiap perubahan masuk ke outbox (`niaga_events`) dan dikirim ke pelanggan event (email, print station,
|
|
35
|
+
kode Anda sendiri) dengan percobaan ulang; pengiriman yang gagal tampil di admin dan bisa dikirim lagi.
|
|
36
|
+
- **Notifikasi**: email ke pembeli saat dibayar, dikirim, sampai, dan refund, lewat penyedia email EmDash.
|
|
37
|
+
- **Laporan**: penjualan per hari, produk dan varian terlaris, metode bayar, kurir, kota, voucher, pembeli yang kembali,
|
|
38
|
+
dan kecepatan kirim, untuk owner dan super admin, dengan ekspor CSV.
|
|
39
|
+
- **Modul biaya operator** (opsional): untuk operator yang menjalankan toko untuk brand. Tarif dibekukan per pesanan,
|
|
40
|
+
biaya gateway asli dari provider kalau tersedia, tagihan bulanan dalam PDF dan CSV.
|
|
41
|
+
- **Pengaturan toko**: zona waktu, mata uang, bahasa (Indonesia dan Inggris), awalan kode pesanan dan invoice, alamat
|
|
42
|
+
pickup, kurir yang ditawarkan, jam batas kirim hari yang sama.
|
|
43
|
+
|
|
44
|
+
## Kebutuhan
|
|
45
|
+
|
|
46
|
+
- EmDash 1.7 atau 1.8 di Astro 7.4 dengan adapter Cloudflare, satu database D1, dan satu bucket R2.
|
|
47
|
+
- Paket Cloudflare Workers Paid (situs EmDash dengan plugin native lebih besar dari batas 3 MiB paket gratis).
|
|
48
|
+
- Node 22 atau lebih baru untuk build, disarankan pnpm.
|
|
49
|
+
- Satu plugin pembayaran dan satu plugin pengiriman, misalnya
|
|
50
|
+
[emdash-niaga-payment-mayar](https://github.com/baguskto/emdash-niaga-payment-mayar) dan
|
|
51
|
+
[emdash-niaga-shipping-biteship](https://github.com/baguskto/emdash-niaga-shipping-biteship).
|
|
52
|
+
|
|
53
|
+
## Instalasi
|
|
54
|
+
|
|
55
|
+
Sampai rilis npm, pasang dari GitHub:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pnpm add "github:baguskto/emdash-niaga-commerce#path:/packages/core" \
|
|
59
|
+
"github:baguskto/emdash-niaga-commerce#path:/packages/contracts" \
|
|
60
|
+
github:baguskto/emdash-niaga-payment-mayar \
|
|
61
|
+
github:baguskto/emdash-niaga-shipping-biteship
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
pnpm hanya mem-build paket git kalau diizinkan. Kalau berhenti dengan `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`, tambahkan
|
|
65
|
+
kunci persis yang dicetaknya ke `allowBuilds` di `pnpm-workspace.yaml`, lalu jalankan instalasi lagi. Setelah rilis npm:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pnpm add emdash-niaga-commerce emdash-niaga-commerce-contracts emdash-niaga-payment-mayar emdash-niaga-shipping-biteship
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Pasang di situs
|
|
72
|
+
|
|
73
|
+
`astro.config.mjs`:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import cloudflare from "@astrojs/cloudflare";
|
|
77
|
+
import react from "@astrojs/react";
|
|
78
|
+
import { d1, r2 } from "@emdash-cms/cloudflare";
|
|
79
|
+
import { defineConfig } from "astro/config";
|
|
80
|
+
import emdash from "emdash/astro";
|
|
81
|
+
import { niagaCommerce, niagaStorefront } from "emdash-niaga-commerce";
|
|
82
|
+
import { niagaPaymentMayar } from "emdash-niaga-payment-mayar";
|
|
83
|
+
import { niagaShippingBiteship } from "emdash-niaga-shipping-biteship";
|
|
84
|
+
|
|
85
|
+
export default defineConfig({
|
|
86
|
+
output: "server",
|
|
87
|
+
adapter: cloudflare(),
|
|
88
|
+
integrations: [
|
|
89
|
+
react(),
|
|
90
|
+
emdash({
|
|
91
|
+
database: d1({ binding: "DB", session: "auto" }),
|
|
92
|
+
storage: r2({ binding: "MEDIA" }),
|
|
93
|
+
plugins: [
|
|
94
|
+
niagaPaymentMayar({ mode: "production" }),
|
|
95
|
+
niagaShippingBiteship(),
|
|
96
|
+
niagaCommerce({
|
|
97
|
+
// Nilai awal; semuanya bisa diubah nanti di Niaga > Store settings, dan yang di sana yang dipakai.
|
|
98
|
+
store: {
|
|
99
|
+
name: "Toko Saya",
|
|
100
|
+
siteUrl: "https://toko-saya.id",
|
|
101
|
+
orderPrefix: "TS",
|
|
102
|
+
origin: { name: "Gudang", phone: "+6281200000000", line1: "Jl. Contoh No. 1", postalCode: "40132", country: "ID" },
|
|
103
|
+
shipping: { provider: null, couriers: ["jne", "sicepat", "jnt", "anteraja"] },
|
|
104
|
+
},
|
|
105
|
+
superadmins: ["anda@contoh.id"],
|
|
106
|
+
owners: ["owner@contoh.id"],
|
|
107
|
+
}),
|
|
108
|
+
],
|
|
109
|
+
}),
|
|
110
|
+
// API storefront di /api/niaga/* dan webhook di /api/webhooks/<provider>.
|
|
111
|
+
niagaStorefront(),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Urutan plugin tidak berpengaruh: provider mendaftar ke registry bersama, dan core mencarinya saat dibutuhkan.
|
|
117
|
+
`niagaStorefront({ basePath, webhookPath })` memindahkan kedua kelompok route kalau tema Anda butuh path lain.
|
|
118
|
+
|
|
119
|
+
`wrangler.jsonc` butuh binding D1 dan R2 yang sudah dipakai EmDash, dan cron trigger untuk tugas terjadwal Niaga
|
|
120
|
+
(kedaluwarsa pembayaran tiap menit, pelacakan tiap dua jam, sinkron biaya tiap hari):
|
|
121
|
+
|
|
122
|
+
```jsonc
|
|
123
|
+
{
|
|
124
|
+
"d1_databases": [{ "binding": "DB", "database_name": "toko-saya" }],
|
|
125
|
+
"r2_buckets": [{ "binding": "MEDIA", "bucket_name": "toko-saya-media" }],
|
|
126
|
+
"triggers": { "crons": ["* * * * *"] }
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Opsi
|
|
131
|
+
|
|
132
|
+
| Opsi | Bawaan | Fungsinya |
|
|
133
|
+
| --- | --- | --- |
|
|
134
|
+
| `store` | bawaan core | Pengaturan toko awal (lihat `StoreSettings`). Halaman Store settings di admin menimpanya per kunci |
|
|
135
|
+
| `d1Binding` | `"DB"` | Binding D1 berisi tabel EmDash dan tabel `niaga_` |
|
|
136
|
+
| `queueBinding` | tidak ada | Queue untuk webhook: route langsung menjawab dan consumer queue Anda memanggil `processQueuedWebhook(msg)` dari `emdash-niaga-commerce/host`. Tanpa queue, webhook diproses langsung; sisanya diproses tugas tiap menit |
|
|
137
|
+
| `migrations` | `"auto"` | `"auto"` menjalankan migrasi pada request pertama sebuah isolate; `"manual"` mengharapkan `niaga migrate` saat deploy |
|
|
138
|
+
| `superadmins`, `owners` | tidak ada | Mengisi peran commerce sekali; baris yang diubah di admin tidak pernah ditimpa |
|
|
139
|
+
| `providerPlugins` | `{}` | Id provider ke id plugin EmDash, untuk plugin provider yang tidak bernama `niaga-<jenis>-<id>` |
|
|
140
|
+
| `env` | lihat di bawah | Nama variabel Worker, kalau milik Anda berbeda |
|
|
141
|
+
|
|
142
|
+
## Migrasi database
|
|
143
|
+
|
|
144
|
+
Semua tabel berawalan `niaga_` dan berada di database D1 yang sama dengan EmDash. Dengan `migrations: "auto"` (bawaan)
|
|
145
|
+
skema dipasang pada request pertama tiap isolate; aman diulang dan cepat. Untuk menjalankannya saat deploy:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pnpm exec niaga migrate --print # SQL-nya, untuk diperiksa atau dijalankan sendiri
|
|
149
|
+
pnpm exec niaga migrate --database DB --remote # lewat wrangler d1 execute
|
|
150
|
+
pnpm exec niaga migrate --database DB --local # database dev lokal
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Secret dan pengaturan
|
|
154
|
+
|
|
155
|
+
Kredensial provider disimpan di plugin provider: pasang sebagai secret Worker (nama env ada di README tiap plugin,
|
|
156
|
+
misalnya `MAYAR_API_KEY`) atau di halaman pengaturan plugin di admin EmDash. Secret Worker menang atas pengaturan.
|
|
157
|
+
Core membaca:
|
|
158
|
+
|
|
159
|
+
| Variabel Worker | Untuk |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `TURNSTILE_SECRET` | Cek Turnstile saat checkout (opsional; tanpa ini checkout jalan tanpa cek) |
|
|
162
|
+
| `GOOGLE_CLIENT_ID` | Masuk dengan Google untuk pembeli (opsional; tanpa ini akun mati) |
|
|
163
|
+
| `PUBLIC_SITE_URL` | URL toko di email, invoice, dan link kembali dari pembayaran (menimpa pengaturan) |
|
|
164
|
+
|
|
165
|
+
Pasang dengan `wrangler secret put NAMA`. Jangan pernah di-commit; untuk `astro dev` taruh di `.dev.vars`, yang
|
|
166
|
+
diabaikan git.
|
|
167
|
+
|
|
168
|
+
## Login, peran, dan Cloudflare Access
|
|
169
|
+
|
|
170
|
+
Niaga memakai login EmDash. Di produksi, taruh admin di belakang Cloudflare Access dan biarkan EmDash memetakan grup
|
|
171
|
+
identity provider Anda ke level perannya. Di atas itu, Niaga punya tiga peran commerce:
|
|
172
|
+
|
|
173
|
+
| Peran | Bisa |
|
|
174
|
+
| --- | --- |
|
|
175
|
+
| Staff | Today, Orders, Products, Returns, Vouchers (tanpa angka penjualan) |
|
|
176
|
+
| Owner | Semua yang bisa staff, plus Sales, Store settings, impor katalog, dan batch voucher baru |
|
|
177
|
+
| Super admin | Semuanya, plus modul biaya, tagihan, dan daftar orang dan peran |
|
|
178
|
+
|
|
179
|
+
Baris di daftar orang Niaga (Store settings) menentukan peran berdasarkan email. Tanpa baris, Editor EmDash menjadi
|
|
180
|
+
owner, sedangkan Contributor atau Author menjadi staff. Super admin selalu berupa baris eksplisit (isi dengan
|
|
181
|
+
`superadmins`), kecuali selama belum ada super admin sama sekali, saat Admin EmDash dihitung sebagai super admin supaya
|
|
182
|
+
peran pertama bisa diatur. Super admin aktif terakhir tidak bisa dihapus, dan tidak ada yang bisa mengubah barisnya
|
|
183
|
+
sendiri. Setiap panggilan API admin memeriksa peran lagi di server.
|
|
184
|
+
|
|
185
|
+
## Halaman admin
|
|
186
|
+
|
|
187
|
+
Halaman muncul di bawah **Niaga** di sidebar admin EmDash (`/_emdash/admin/plugins/niaga-commerce/...`). Halaman memakai
|
|
188
|
+
design token EmDash sendiri, jadi ikut tema terang dan gelapnya, dan dibuat untuk HP 390 px lebih dulu.
|
|
189
|
+
|
|
190
|
+
| Halaman | Untuk apa | Tangkapan layar |
|
|
191
|
+
| --- | --- | --- |
|
|
192
|
+
| Today | Antrean kerja: pesan kurir, cetak, serahkan, masalah, retur terbuka, stok menipis | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/today-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/today-1440.png) |
|
|
193
|
+
| Orders | Tab tahap dengan jumlah, cari, filter, aksi massal; halaman pesanan dengan langkah berikutnya, data label, timeline | [daftar 390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/orders-390.png), [daftar 1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/orders-1440.png), [pesanan 390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/order-detail-390.png), [pesanan 1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/order-detail-1440.png) |
|
|
194
|
+
| Products | Daftar dengan stok menipis; lembar varian, pilihan, foto dari pustaka media, log stok | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/products-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/products-1440.png), [lembar 390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/variant-sheet-390.png), [lembar 1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/variant-sheet-1440.png) |
|
|
195
|
+
| Returns | Kasus terbuka dan selesai, kembalikan ke stok, tutup dengan keputusan | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/returns-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/returns-1440.png) |
|
|
196
|
+
| Vouchers | Batch dengan pemakaian, jeda atau akhiri, kode sebagai CSV, batch baru | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/vouchers-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/vouchers-1440.png) |
|
|
197
|
+
| Sales | Owner dan super admin: satu periode dibanding periode sebelumnya, per hari, yang terjual, CSV | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/reports-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/reports-1440.png) |
|
|
198
|
+
| Fees | Super admin, modul biaya aktif: transaksi, ringkasan, tagihan, tarif | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/fees-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/fees-1440.png) |
|
|
199
|
+
| Store settings | Toko, bahasa dan wilayah, checkout, provider, alamat pickup, notifikasi, peran, pengiriman event | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/settings-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/settings-1440.png) |
|
|
200
|
+
|
|
201
|
+
Admin mengikuti bahasa EmDash kalau Bahasa Indonesia atau Inggris, selain itu bahasa bawaan toko.
|
|
202
|
+
|
|
203
|
+
## API storefront dan webhook
|
|
204
|
+
|
|
205
|
+
`niagaStorefront()` menambahkan route JSON yang dipanggil tema dari browser (atau impor `emdash-niaga-commerce/server`
|
|
206
|
+
di halaman Astro dan baca database langsung, seperti `examples/basic-store`):
|
|
207
|
+
|
|
208
|
+
| Route | Fungsinya |
|
|
209
|
+
| --- | --- |
|
|
210
|
+
| `GET /api/niaga/catalog?q=&category=&sort=` | Produk dan kategori |
|
|
211
|
+
| `GET /api/niaga/products/<slug>` | Data halaman produk dan JSON-LD |
|
|
212
|
+
| `GET, POST /api/niaga/cart` | Keranjang di cookie httpOnly: tambah, ubah, hapus, voucher, kosongkan |
|
|
213
|
+
| `GET /api/niaga/areas?q=` | Cari area dari plugin pengiriman |
|
|
214
|
+
| `POST /api/niaga/rates` | Ongkir untuk isi keranjang |
|
|
215
|
+
| `POST /api/niaga/checkout` | Membuat pesanan, mengunci stok, mengembalikan URL bayar |
|
|
216
|
+
| `GET /api/niaga/orders/<kode>?t=<token>` | Data halaman pesanan pembeli (pesanan belum dibayar dicek ulang ke gateway) |
|
|
217
|
+
| `GET /api/niaga/vouchers/<kode>` | Halaman voucher; pembukaan pertama memulai masa berlaku kode kartu |
|
|
218
|
+
| `/api/niaga/auth/google/*`, `/api/niaga/account*` | Masuk dengan Google (opsional) dan akun pembeli |
|
|
219
|
+
|
|
220
|
+
Penolakan dari provider (misalnya kode pos yang tidak dikenal kurir) dijawab dengan status 502, `error.code:
|
|
221
|
+
"provider"`, dan alasan dari provider, supaya tema bisa menampilkannya.
|
|
222
|
+
|
|
223
|
+
Gateway dan kurir mengirim ke `/api/webhooks/<id provider>`, misalnya `/api/webhooks/mayar` dan `/api/webhooks/biteship`.
|
|
224
|
+
Setiap kiriman diverifikasi oleh providernya, disimpan sekali per id event, dan diproses berurutan; webhook pembayaran
|
|
225
|
+
tidak pernah dipercaya begitu saja dan status bayar selalu dibaca ulang dari gateway.
|
|
226
|
+
|
|
227
|
+
## Print station dan kode Anda sendiri
|
|
228
|
+
|
|
229
|
+
Core mengisi document source di registry, jadi plugin cetak seperti
|
|
230
|
+
[emdash-niaga-autoprint](https://github.com/baguskto/emdash-niaga-autoprint) membaca dokumen pesanan dan label kurir
|
|
231
|
+
tanpa berbicara dengan kurir. Untuk bereaksi pada pesanan dari kode Anda sendiri, berlangganan event:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import { subscribe } from "emdash-niaga-commerce-contracts";
|
|
235
|
+
|
|
236
|
+
subscribe({ subscriber: "sheet-saya", types: ["order.paid"], handle: async (event) => { /* ... */ } });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Setiap pelanggan punya kursor sendiri, dicoba ulang dengan jeda, dan diparkir setelah gagal berulang kali; kiriman yang
|
|
240
|
+
diparkir tampil di Store settings dengan tombol untuk mengirim lagi.
|
|
241
|
+
|
|
242
|
+
## Coba di lokal
|
|
243
|
+
|
|
244
|
+
`examples/basic-store` di repositori ini adalah situs EmDash lengkap dengan provider pembayaran dan pengiriman tiruan:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pnpm install && pnpm build
|
|
248
|
+
cd examples/basic-store
|
|
249
|
+
pnpm dev # http://localhost:4410, admin di /_emdash/admin (login dev)
|
|
250
|
+
bash scripts/e2e.sh # checkout, bayar lewat webhook, pesan kurir, label, cetak, serahkan: PASS atau FAIL
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
`NIAGA_PROVIDERS=live pnpm dev` menjalankan toko yang sama dengan Mayar dan Biteship (kredensial di `.dev.vars`).
|
|
254
|
+
|
|
255
|
+
## Pengembangan
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pnpm install
|
|
259
|
+
pnpm --filter emdash-niaga-commerce typecheck
|
|
260
|
+
pnpm --filter emdash-niaga-commerce test
|
|
261
|
+
pnpm --filter emdash-niaga-commerce build
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Tes berjalan di SQLite bawaan Node lewat shim D1 kecil (`emdash-niaga-commerce/testing`), dengan provider tiruan dari
|
|
265
|
+
contracts. Setelah mengubah `migrations/*.sql`, jalankan `pnpm --filter emdash-niaga-commerce gen`.
|
|
266
|
+
|
|
267
|
+
## Lisensi
|
|
268
|
+
|
|
269
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,3 +1,269 @@
|
|
|
1
|
-
#
|
|
1
|
+
# emdash-niaga-commerce
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An online store for [EmDash](https://github.com/emdash-cms/emdash) sites, built for Indonesian sellers: products with a
|
|
4
|
+
Shopee-style variant sheet, stock that never oversells, cart and checkout, an order work queue for packing on a phone,
|
|
5
|
+
returns and failed deliveries, vouchers, buyer accounts, email notifications, sales reports and an optional operator
|
|
6
|
+
fee module. Payments, shipping and printing come from separate plugins that implement
|
|
7
|
+
[emdash-niaga-commerce-contracts](https://github.com/baguskto/emdash-niaga-commerce/tree/main/packages/contracts), so a store can swap Mayar for another gateway or Biteship for another
|
|
8
|
+
carrier without touching the store.
|
|
9
|
+
|
|
10
|
+
Bahasa Indonesia: [README.id.md](README.id.md).
|
|
11
|
+
|
|
12
|
+
**Status: 0.1, in development.** It runs end to end (see `examples/basic-store`) and is tested, but it is not yet on npm
|
|
13
|
+
and has not run a production store.
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## What it does
|
|
18
|
+
|
|
19
|
+
- **Catalogue**: products, up to two option types (colour, size), a variant sheet with set-all and paste-a-column,
|
|
20
|
+
photos and videos picked from the EmDash media library, categories, Indonesian and English names, search, and
|
|
21
|
+
`importCatalog()` for a JSON catalogue (Shopee exports map onto it).
|
|
22
|
+
- **Stock**: every unit is reserved when a buyer checks out, in the same D1 batch as the order. A database constraint
|
|
23
|
+
(`reserved <= stock`) refuses the last unit twice, so two buyers can never pay for one item. Unpaid orders give their
|
|
24
|
+
units back when the payment deadline passes. Every change is in a stock log.
|
|
25
|
+
- **Checkout**: guest checkout by WhatsApp number, live courier rates from the shipping plugin, vouchers, free shipping
|
|
26
|
+
from a minimum spend, Cloudflare Turnstile, and a hosted payment page from the payment plugin.
|
|
27
|
+
- **Orders**: a work queue in the order things happen: book the courier, print the label, hand over. Bulk actions,
|
|
28
|
+
address edits before booking, cancelling an unpaid order (its invoice is closed at the gateway), re-check payment.
|
|
29
|
+
- **Returns and failed deliveries**: open a case, restock what came back, close it with resend, refund, exchange,
|
|
30
|
+
store credit or no action.
|
|
31
|
+
- **Vouchers**: batches of single-use card codes or one campaign code, percent, amount or shipping discounts, minimum
|
|
32
|
+
spend, first order only, per-buyer limits and quotas, with a CSV of codes for printing.
|
|
33
|
+
- **Buyer accounts** (optional): Google sign-in, order history and saved addresses. Guests never need an account.
|
|
34
|
+
- **Events**: every change goes into an outbox (`niaga_events`) and is delivered to subscribers (emails, the print
|
|
35
|
+
station, your own code) with retries; failed deliveries show in the admin and can be sent again.
|
|
36
|
+
- **Notifications**: emails to buyers on payment, shipping, delivery and refunds through EmDash's email provider.
|
|
37
|
+
- **Reports**: sales by day, best products and variants, payment methods, couriers, cities, vouchers, returning
|
|
38
|
+
buyers and dispatch speed, for owners and super admins, with CSV export.
|
|
39
|
+
- **Operator fee module** (optional): for an operator who runs stores for brands. Frozen rates per order, gateway fees
|
|
40
|
+
from the provider when it reports them, monthly statements with PDF and CSV.
|
|
41
|
+
- **Store settings**: time zone, currency, languages (English and Indonesian), order and invoice prefixes, pickup
|
|
42
|
+
address, couriers offered, dispatch cut-off.
|
|
43
|
+
|
|
44
|
+
## Requirements
|
|
45
|
+
|
|
46
|
+
- EmDash 1.7 or 1.8 on Astro 7.4 with the Cloudflare adapter, a D1 database and an R2 bucket.
|
|
47
|
+
- A Cloudflare Workers Paid plan (an EmDash site with native plugins is larger than the free plan's 3 MiB).
|
|
48
|
+
- Node 22 or later for builds, pnpm recommended.
|
|
49
|
+
- A payment plugin and a shipping plugin, for example
|
|
50
|
+
[emdash-niaga-payment-mayar](https://github.com/baguskto/emdash-niaga-payment-mayar) and
|
|
51
|
+
[emdash-niaga-shipping-biteship](https://github.com/baguskto/emdash-niaga-shipping-biteship).
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
Until the npm release, install from GitHub:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pnpm add "github:baguskto/emdash-niaga-commerce#path:/packages/core" \
|
|
59
|
+
"github:baguskto/emdash-niaga-commerce#path:/packages/contracts" \
|
|
60
|
+
github:baguskto/emdash-niaga-payment-mayar \
|
|
61
|
+
github:baguskto/emdash-niaga-shipping-biteship
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
pnpm builds git packages on install only when allowed. If it stops with `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`, add the
|
|
65
|
+
exact key it prints to `allowBuilds` in `pnpm-workspace.yaml` and run the install again. After the npm release:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pnpm add emdash-niaga-commerce emdash-niaga-commerce-contracts emdash-niaga-payment-mayar emdash-niaga-shipping-biteship
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Wire it into the site
|
|
72
|
+
|
|
73
|
+
`astro.config.mjs`:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import cloudflare from "@astrojs/cloudflare";
|
|
77
|
+
import react from "@astrojs/react";
|
|
78
|
+
import { d1, r2 } from "@emdash-cms/cloudflare";
|
|
79
|
+
import { defineConfig } from "astro/config";
|
|
80
|
+
import emdash from "emdash/astro";
|
|
81
|
+
import { niagaCommerce, niagaStorefront } from "emdash-niaga-commerce";
|
|
82
|
+
import { niagaPaymentMayar } from "emdash-niaga-payment-mayar";
|
|
83
|
+
import { niagaShippingBiteship } from "emdash-niaga-shipping-biteship";
|
|
84
|
+
|
|
85
|
+
export default defineConfig({
|
|
86
|
+
output: "server",
|
|
87
|
+
adapter: cloudflare(),
|
|
88
|
+
integrations: [
|
|
89
|
+
react(),
|
|
90
|
+
emdash({
|
|
91
|
+
database: d1({ binding: "DB", session: "auto" }),
|
|
92
|
+
storage: r2({ binding: "MEDIA" }),
|
|
93
|
+
plugins: [
|
|
94
|
+
niagaPaymentMayar({ mode: "production" }),
|
|
95
|
+
niagaShippingBiteship(),
|
|
96
|
+
niagaCommerce({
|
|
97
|
+
// Defaults; every value can be changed later in Niaga > Store settings, which wins.
|
|
98
|
+
store: {
|
|
99
|
+
name: "Toko Saya",
|
|
100
|
+
siteUrl: "https://toko-saya.id",
|
|
101
|
+
orderPrefix: "TS",
|
|
102
|
+
origin: { name: "Gudang", phone: "+6281200000000", line1: "Jl. Contoh No. 1", postalCode: "40132", country: "ID" },
|
|
103
|
+
shipping: { provider: null, couriers: ["jne", "sicepat", "jnt", "anteraja"] },
|
|
104
|
+
},
|
|
105
|
+
superadmins: ["you@example.com"],
|
|
106
|
+
owners: ["owner@example.com"],
|
|
107
|
+
}),
|
|
108
|
+
],
|
|
109
|
+
}),
|
|
110
|
+
// Storefront API at /api/niaga/* and webhooks at /api/webhooks/<provider>.
|
|
111
|
+
niagaStorefront(),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The order of plugins does not matter: providers register into a shared registry, and core looks them up when it needs
|
|
117
|
+
them. `niagaStorefront({ basePath, webhookPath })` moves the two route groups if your theme needs other paths.
|
|
118
|
+
|
|
119
|
+
`wrangler.jsonc` needs the D1 and R2 bindings EmDash already uses, and a cron trigger for Niaga's scheduled tasks
|
|
120
|
+
(payment expiry every minute, tracking every two hours, fee sync daily):
|
|
121
|
+
|
|
122
|
+
```jsonc
|
|
123
|
+
{
|
|
124
|
+
"d1_databases": [{ "binding": "DB", "database_name": "my-store" }],
|
|
125
|
+
"r2_buckets": [{ "binding": "MEDIA", "bucket_name": "my-store-media" }],
|
|
126
|
+
"triggers": { "crons": ["* * * * *"] }
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Options
|
|
131
|
+
|
|
132
|
+
| Option | Default | What it does |
|
|
133
|
+
| --- | --- | --- |
|
|
134
|
+
| `store` | built-in defaults | Store settings to start from (see `StoreSettings`). The admin's Store settings page overrides them key by key |
|
|
135
|
+
| `d1Binding` | `"DB"` | D1 binding with EmDash's tables and the `niaga_` tables |
|
|
136
|
+
| `queueBinding` | none | Queue for webhooks: the route answers at once and your queue consumer calls `processQueuedWebhook(msg)` from `emdash-niaga-commerce/host`. Without it webhooks are processed inline; anything left over is processed by the minute task |
|
|
137
|
+
| `migrations` | `"auto"` | `"auto"` applies migrations on an isolate's first request; `"manual"` expects `niaga migrate` in your deploy |
|
|
138
|
+
| `superadmins`, `owners` | none | Seeds the commerce roles once; rows changed in the admin are never overwritten |
|
|
139
|
+
| `providerPlugins` | `{}` | Provider id to EmDash plugin id, for provider plugins not named `niaga-<kind>-<id>` |
|
|
140
|
+
| `env` | see below | Names of Worker variables, if yours differ |
|
|
141
|
+
|
|
142
|
+
## Database migrations
|
|
143
|
+
|
|
144
|
+
All tables start with `niaga_` and live in the same D1 database as EmDash. With `migrations: "auto"` (the default) the
|
|
145
|
+
schema is applied on the first request of each isolate; it is idempotent and quick. To run them in your deploy instead:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pnpm exec niaga migrate --print # the SQL, to review or apply yourself
|
|
149
|
+
pnpm exec niaga migrate --database DB --remote # through wrangler d1 execute
|
|
150
|
+
pnpm exec niaga migrate --database DB --local # the local dev database
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Secrets and settings
|
|
154
|
+
|
|
155
|
+
Provider credentials live with the provider plugin: set them as Worker secrets (the env names are in each plugin's
|
|
156
|
+
README, for example `MAYAR_API_KEY`) or in the plugin's settings page in the EmDash admin. A Worker secret wins over a
|
|
157
|
+
setting. Core reads:
|
|
158
|
+
|
|
159
|
+
| Worker variable | Needed for |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `TURNSTILE_SECRET` | Turnstile check on checkout (optional; without it checkout runs without the check) |
|
|
162
|
+
| `GOOGLE_CLIENT_ID` | Google sign-in for buyers (optional; without it accounts are off) |
|
|
163
|
+
| `PUBLIC_SITE_URL` | The storefront URL in emails, invoices and payment return links (overrides the setting) |
|
|
164
|
+
|
|
165
|
+
Set them with `wrangler secret put NAME`. Never commit them; for `astro dev` put them in `.dev.vars`, which is
|
|
166
|
+
git-ignored.
|
|
167
|
+
|
|
168
|
+
## Sign-in, roles and Cloudflare Access
|
|
169
|
+
|
|
170
|
+
Niaga uses EmDash's own login. In production, put the admin behind Cloudflare Access and let EmDash map your identity
|
|
171
|
+
provider's groups to its role levels. On top of that, Niaga has three commerce roles:
|
|
172
|
+
|
|
173
|
+
| Role | Can |
|
|
174
|
+
| --- | --- |
|
|
175
|
+
| Staff | Today, Orders, Products, Returns, Vouchers (no sales figures) |
|
|
176
|
+
| Owner | Everything staff can, plus Sales, Store settings, catalogue import and new voucher batches |
|
|
177
|
+
| Super admin | Everything, plus the fee module, statements and the list of people and roles |
|
|
178
|
+
|
|
179
|
+
A row in Niaga's list of people (Store settings) decides the role by email. Without a row, an EmDash Editor is an owner
|
|
180
|
+
and a Contributor or Author is staff. Super admin is only ever an explicit row (seed it with `superadmins`), except
|
|
181
|
+
while no super admin exists at all, when an EmDash Admin counts as one so the first roles can be set. The last active
|
|
182
|
+
super admin can never be removed, and nobody changes their own row. Every admin API call checks the role again on the
|
|
183
|
+
server.
|
|
184
|
+
|
|
185
|
+
## Admin pages
|
|
186
|
+
|
|
187
|
+
The pages appear under **Niaga** in the EmDash admin sidebar (`/_emdash/admin/plugins/niaga-commerce/...`). They use
|
|
188
|
+
EmDash's own design tokens, so they follow its light and dark themes, and they are built for a 390 px phone first.
|
|
189
|
+
|
|
190
|
+
| Page | What it is for | Screenshots |
|
|
191
|
+
| --- | --- | --- |
|
|
192
|
+
| Today | The work queue: book the courier, print, hand over, problems, open returns, low stock | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/today-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/today-1440.png) |
|
|
193
|
+
| Orders | Stage tabs with counts, search, filters, bulk actions; the order page with its next step, label data, timeline | [list 390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/orders-390.png), [list 1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/orders-1440.png), [order 390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/order-detail-390.png), [order 1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/order-detail-1440.png) |
|
|
194
|
+
| Products | The list with low stock; the variant sheet, options, photos from the media library, stock log | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/products-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/products-1440.png), [sheet 390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/variant-sheet-390.png), [sheet 1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/variant-sheet-1440.png) |
|
|
195
|
+
| Returns | Open and closed cases, restock, close with a decision | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/returns-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/returns-1440.png) |
|
|
196
|
+
| Vouchers | Batches with usage, pause or end, codes as CSV, new batch | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/vouchers-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/vouchers-1440.png) |
|
|
197
|
+
| Sales | Owners and super admins: a period against the one before, day by day, what sold, CSV | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/reports-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/reports-1440.png) |
|
|
198
|
+
| Fees | Super admins, fee module on: transactions, summary, statements, rates | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/fees-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/fees-1440.png) |
|
|
199
|
+
| Store settings | Store, language and region, checkout, providers, pickup address, notifications, roles, event deliveries | [390](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/settings-390.png), [1440](https://github.com/baguskto/emdash-niaga-commerce/blob/main/docs/screenshots/settings-1440.png) |
|
|
200
|
+
|
|
201
|
+
The admin follows EmDash's language when it is English or Indonesian, otherwise the store's default language.
|
|
202
|
+
|
|
203
|
+
## Storefront API and webhooks
|
|
204
|
+
|
|
205
|
+
`niagaStorefront()` adds JSON routes your theme calls from the browser (or import `emdash-niaga-commerce/server` in
|
|
206
|
+
Astro pages and read the database directly, as `examples/basic-store` does):
|
|
207
|
+
|
|
208
|
+
| Route | What it does |
|
|
209
|
+
| --- | --- |
|
|
210
|
+
| `GET /api/niaga/catalog?q=&category=&sort=` | Products and categories |
|
|
211
|
+
| `GET /api/niaga/products/<slug>` | Product page data and JSON-LD |
|
|
212
|
+
| `GET, POST /api/niaga/cart` | The cart in an httpOnly cookie: add, set, remove, voucher, clear |
|
|
213
|
+
| `GET /api/niaga/areas?q=` | Area search from the shipping plugin |
|
|
214
|
+
| `POST /api/niaga/rates` | Courier rates for the cart |
|
|
215
|
+
| `POST /api/niaga/checkout` | Places the order, reserves stock, returns the payment URL |
|
|
216
|
+
| `GET /api/niaga/orders/<code>?t=<token>` | The buyer's order page data (re-checks an unpaid order with the gateway) |
|
|
217
|
+
| `GET /api/niaga/vouchers/<code>` | Voucher landing; the first open starts a card code's validity |
|
|
218
|
+
| `/api/niaga/auth/google/*`, `/api/niaga/account*` | Optional Google sign-in and the buyer's account |
|
|
219
|
+
|
|
220
|
+
A provider refusal (for example a postal code the carrier does not know) comes back as status 502 with
|
|
221
|
+
`error.code: "provider"` and the provider's reason, so the theme can show it.
|
|
222
|
+
|
|
223
|
+
Gateways and carriers post to `/api/webhooks/<provider id>`, for example `/api/webhooks/mayar` and
|
|
224
|
+
`/api/webhooks/biteship`. Every delivery is verified by its provider, stored once by event id and processed in order;
|
|
225
|
+
a payment webhook never trusts the payload and always re-reads the payment from the gateway.
|
|
226
|
+
|
|
227
|
+
## Print stations and your own code
|
|
228
|
+
|
|
229
|
+
Core sets the registry's document source, so a print plugin such as
|
|
230
|
+
[emdash-niaga-autoprint](https://github.com/baguskto/emdash-niaga-autoprint) reads order documents and carrier labels
|
|
231
|
+
without talking to a carrier. To react to orders in your own code, subscribe to events:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import { subscribe } from "emdash-niaga-commerce-contracts";
|
|
235
|
+
|
|
236
|
+
subscribe({ subscriber: "my-sheet", types: ["order.paid"], handle: async (event) => { /* ... */ } });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Each subscriber has its own cursor, retries with backoff, and is parked after repeated failures; parked deliveries are
|
|
240
|
+
listed in Store settings with a button to send them again.
|
|
241
|
+
|
|
242
|
+
## Try it locally
|
|
243
|
+
|
|
244
|
+
`examples/basic-store` in this repository is a complete EmDash site with mock payment and shipping providers:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pnpm install && pnpm build
|
|
248
|
+
cd examples/basic-store
|
|
249
|
+
pnpm dev # http://localhost:4410, admin at /_emdash/admin (dev sign-in)
|
|
250
|
+
bash scripts/e2e.sh # checkout, pay by webhook, book, label, print, hand over: PASS or FAIL per step
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
`NIAGA_PROVIDERS=live pnpm dev` runs the same store with Mayar and Biteship instead (credentials in `.dev.vars`).
|
|
254
|
+
|
|
255
|
+
## Development
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
pnpm install
|
|
259
|
+
pnpm --filter emdash-niaga-commerce typecheck
|
|
260
|
+
pnpm --filter emdash-niaga-commerce test
|
|
261
|
+
pnpm --filter emdash-niaga-commerce build
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Tests run on Node's built-in SQLite through a small D1 shim (`emdash-niaga-commerce/testing`), with the contracts'
|
|
265
|
+
mock providers. After editing `migrations/*.sql`, run `pnpm --filter emdash-niaga-commerce gen`.
|
|
266
|
+
|
|
267
|
+
## Licence
|
|
268
|
+
|
|
269
|
+
MIT
|
package/bin/niaga.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* niaga migrate: the deploy-step mode for the core migrations (the other mode, `auto`, runs them on the first request).
|
|
4
|
+
*
|
|
5
|
+
* npx niaga migrate --print # SQL on stdout
|
|
6
|
+
* npx niaga migrate --database DB --local # wrangler d1 execute DB --local --file <tmp>
|
|
7
|
+
* npx niaga migrate --database DB --remote --wrangler-config wrangler.jsonc
|
|
8
|
+
*
|
|
9
|
+
* Every statement is re-runnable and each migration is recorded in niaga_migrations, so running it twice is harmless.
|
|
10
|
+
*/
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
const [command] = args;
|
|
18
|
+
const flag = (name) => args.includes(`--${name}`);
|
|
19
|
+
const value = (name) => {
|
|
20
|
+
const i = args.indexOf(`--${name}`);
|
|
21
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (command !== "migrate") {
|
|
25
|
+
console.log("usage: niaga migrate [--print] [--database <binding or name>] [--local | --remote] [--wrangler-config <file>]");
|
|
26
|
+
process.exit(command ? 1 : 0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { migrationScript } = await import("../dist/server/migrate.js");
|
|
30
|
+
const sql = migrationScript();
|
|
31
|
+
if (flag("print")) {
|
|
32
|
+
process.stdout.write(sql);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const database = value("database") ?? "DB";
|
|
37
|
+
const dir = mkdtempSync(join(tmpdir(), "niaga-migrate-"));
|
|
38
|
+
const file = join(dir, "niaga-migrations.sql");
|
|
39
|
+
writeFileSync(file, sql);
|
|
40
|
+
const wranglerArgs = ["wrangler", "d1", "execute", database, "--file", file, "--yes"];
|
|
41
|
+
if (flag("remote")) wranglerArgs.push("--remote");
|
|
42
|
+
else wranglerArgs.push("--local");
|
|
43
|
+
const config = value("wrangler-config");
|
|
44
|
+
if (config) wranglerArgs.push("--config", config);
|
|
45
|
+
const res = spawnSync("npx", wranglerArgs, { stdio: "inherit" });
|
|
46
|
+
rmSync(dir, { recursive: true, force: true });
|
|
47
|
+
process.exit(res.status ?? 1);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fees.d.ts","sourceRoot":"","sources":["../../src/admin/fees.tsx"],"names":[],"mappings":"AAwEA,wBAAgB,QAAQ,gCAkIvB"}
|