Dokumentasi Human in The Loop

English

Dokumentasi Pemakaian CrootJS dengan AI Companion dan Human in the loop.

Pindah dari JSCroot? Baca Dari JSCroot ke CrootJS: alamat impor baru, fungsi yang dihapus beserta penggantinya, dan perilaku yang berubah.

Impor setiap modul dari versi yang dipatok, mis. https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js. Untuk produksi pakai .min.js untuk semua impor CrootJS di satu halaman, jangan dicampur dengan .js: api.min.js dan storage.js adalah alamat modul yang berbeda, jadi modul yang diimpor keduanya termuat dua kali dengan state masing-masing. Sejak 0.0.38 berkas .min.js di setiap rilis mengimpor .min.js modul pendampingnya.

Patok versi ke tag (@0.0.39), bukan ke SHA commit dari main. Berkas .min.js buatan kita hanya ada di commit rilis (di branch dist, sejak 0.0.40); untuk SHA dari main, jsDelivr memperkecil sendiri dan api.min.js-nya kembali mengimpor "./storage.js".

Memuat lebih cepat dengan modulepreload

Browser baru tahu sebuah modul butuh modul lain setelah modul itu selesai diunduh, jadi setiap tingkat impor menambah satu kali bolak-balik ke server (sekitar 150 ms di jaringan seluler). Modul berikut mengimpor modul lain:

Modul Ikut dimuat Tingkat
api.js storage.js 1
auth.js cookie.js, api.js, storage.js, url.js, element.js, template.js, useragent.js, qr.js 2
config.js auth.js, cookie.js, api.js, storage.js, url.js, element.js, template.js, useragent.js, qr.js 3
form.js element.js 1
geomeasure.js geo.js 1
georoute.js geo.js, geomeasure.js 2
map.js geo.js 1
mapcluster.js geo.js 1
mapdraw.js geo.js 1
mapheat.js geo.js 1
mapmodel.js model3d.js 1
mapoffline.js mapvector.js 1
maptools.js geomeasure.js, geo.js 2

Tambahkan <link rel="modulepreload"> di <head> untuk modul yang Anda impor dan modul di kolom “Ikut dimuat”, dengan versi dan akhiran .min.js yang sama. Semuanya lalu diunduh bersamaan sejak awal. Contoh untuk halaman yang mengimpor api.min.js:

<link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js" integrity="sha384-FkrcJYDj82Td9axSh3O+A2TIpwCIg67PsrurLGMr5vk4KnL8c+zONZlBbaMEU0Cy">
<link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/storage.min.js" integrity="sha384-I68UpwZkgCfB4R68KBk7oSjwdRZqI+8zHf73gCvG+J2YFk5fxD3kBQjgt45dGk0Z">
<script type="module" src="index.js"></script>

Di landing page croot.js.org, cara ini memajukan request API pertama sekitar 300 ms pada latensi 150 ms. Tabel di atas dibuat dari kode dengan python3 tools/module-deps.py di repo lib.

Atribut integrity pada contoh di atas dijelaskan di bagian berikut. python3 tools/module-deps.py <versi> mencetak baris modulepreload setiap modul lengkap dengan hash-nya.

Mengunci isi berkas dengan integrity (SRI)

Pin versi menjamin URL-nya tetap, bukan isinya: isi di balik @0.0.41 tetap bergantung pada jsDelivr dan GitHub. Dengan hash SRI (Subresource Integrity) browser menghitung hash berkas yang diunduh dan menolak menjalankannya kalau tidak cocok. Sejak 0.0.42 setiap rilis menyertakan integrity.json (https://cdn.jsdelivr.net/gh/crootjs/lib@<versi>/integrity.json): hash sha384 semua .js, .min.js, .css, dan (sejak 0.0.43) .min.css, ditambah modul yang diimpor setiap modul.

integrity di <link rel="modulepreload"> saja tidak cukup: hanya Chromium yang menolak berkas yang berubah, Firefox dan Safari tetap menjalankan modul yang diimpor import. Yang ditegakkan ketiganya adalah import map dengan kunci integrity, dan import map itu juga berlaku untuk import di dalam modul (api.min.js mengimpor storage.min.js). Pasang import map itu dari integrity.js, skrip klasik pertama di <head> (satu-satunya pengecualian aturan modul ES):

<head>
  <script src="integrity.js"></script>
  <link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js" integrity="sha384-FkrcJYDj82Td9axSh3O+A2TIpwCIg67PsrurLGMr5vk4KnL8c+zONZlBbaMEU0Cy">
  <link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/storage.min.js" integrity="sha384-I68UpwZkgCfB4R68KBk7oSjwdRZqI+8zHf73gCvG+J2YFk5fxD3kBQjgt45dGk0Z">
  <script type="module" src="index.js"></script>
</head>
// integrity.js: import map berisi hash SRI modul CrootJS. Skrip klasik yang dimuat paling awal,
// karena Firefox mengabaikan import map yang ditambahkan setelah modul atau preload mulai diunduh.
const map = document.createElement("script");
map.type = "importmap";
map.textContent = JSON.stringify({
    integrity: {
        "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js": "sha384-FkrcJYDj82Td9axSh3O+A2TIpwCIg67PsrurLGMr5vk4KnL8c+zONZlBbaMEU0Cy",
        "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/storage.min.js": "sha384-I68UpwZkgCfB4R68KBk7oSjwdRZqI+8zHf73gCvG+J2YFk5fxD3kBQjgt45dGk0Z"
    }
});
document.currentScript.after(map);

Menaikkan versi dengan bump-pins.py

Versi tertulis di beberapa tempat (import, modulepreload, integrity.js) dan hash berubah setiap versi. Satu yang terlewat berarti modul yang sama diunduh dua kali, atau ditolak browser. tools/bump-pins.py (Python 3 saja, tanpa paket tambahan) mengganti semuanya dalam satu folder:

curl -fsSLO https://raw.githubusercontent.com/crootjs/lib/main/tools/bump-pins.py
python3 bump-pins.py latest .     # atau versi tertentu: python3 bump-pins.py 0.0.42 .

Setiap crootjs/lib@x.y.z di berkas .html, .js, .md, .txt, dan .json menjadi versi baru, dan setiap integrity di samping URL CrootJS diisi hash versi itu (dari integrity.json, atau dari berkas yang diunduh untuk versi sebelum 0.0.42). Kalau satu hash gagal diambil, tidak ada berkas yang ditulis. latest membaca https://croot.js.org/lib/version.json.

Supaya dibuka PR setiap ada versi baru (seperti Dependabot), salin workflow ini ke repo Anda. Di Settings → Actions → General, aktifkan “Allow GitHub Actions to create and approve pull requests”. PR yang dibuat dengan github.token tidak memicu workflow lain, jadi uji CI Anda tidak otomatis berjalan di PR itu.

# .github/workflows/crootjs.yml
name: crootjs
on:
  schedule:
    - cron: "0 2 * * 1"
  workflow_dispatch:
permissions:
  contents: write
  pull-requests: write
jobs:
  bump:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - env:
          GH_TOKEN: $
        run: |
          VERSION=$(curl -fsS https://croot.js.org/lib/version.json | jq -r .version)
          branch="crootjs-$VERSION"
          if git ls-remote --exit-code origin "refs/heads/$branch" > /dev/null; then exit 0; fi
          curl -fsSL https://raw.githubusercontent.com/crootjs/lib/main/tools/bump-pins.py -o /tmp/bump-pins.py
          python3 /tmp/bump-pins.py "$VERSION" .
          if git diff --quiet; then exit 0; fi
          git config user.name "github-actions[bot]"
          git config user.email "41898341+github-actions[bot]@users.noreply.github.com"
          git switch -c "$branch"
          git commit -am "CrootJS $VERSION"
          git push origin "$branch"
          gh pr create --title "CrootJS $VERSION" --body "https://github.com/crootjs/lib/releases/tag/v$VERSION"

Referensi Modul

Dokumentasi per-modul dari crootjs/lib:

Lihat juga: source code lib dan contoh implementasi.

Coding Conventions (Wajib)

Semua kode yang memakai CrootJS — ditulis manusia maupun AI coding agent — wajib memisahkan HTML, CSS, dan JS ke file terpisah, dan JS wajib dimuat sebagai type="module" (kecuali integrity.js untuk SRI). Tidak boleh ada <style>/<script> inline atau atribut onclick/style="" di HTML.

Baca aturan lengkap & alasannya: conventions.md.

Pakai AI coding agent? Unduh CLAUDE.md dan taruh di root project kamu — Claude Code otomatis mengikuti aturan ini.

Landing Page

Pembuatan landing page awal pada alamat.github.io

Buka prompt

buatkan landing page yang responsif untuk platform digital kampus dengan menggunakan HTML, CSS dan JS ES6+ Module dilengkapi dengan meta tag untuk sosial media (termasuk sharing whatsapp yang tampil gambar, judul dan deskripsinya ketika di share)

Human in the loop:

  1. Pastikan terdapat meta tag
     <!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>CrootSS | CSS Mobile Friendly Responsive Component and Template</title>
     <link rel="stylesheet" href="croot.css">
    
         <meta name="description" content="CrootSS: CSS Mobile Friendly Responsive Component and Template." />
         <meta name="keywords" content="CrootSS, CSS, Template, Responsive, Template, Vanilla, html, CSS lib" />
         <meta property="og:image" content="/crootss.png" />
         <!-- Meta Tags untuk Open Graph -->
         <meta property="og:title" content="CrootSS: CSS Mobile Friendly Responsive Component and Template" />
         <meta property="og:description" content="CSS Mobile Friendly Responsive Component and Template" />
         <meta property="og:image" content="https://crootss.if.co.id/crootss.jpeg" />
         <meta property="og:url" content="https://crootss.if.co.id" />
         <meta property="og:type" content="website" />
    
         <!-- Meta Tags untuk Twitter (opsional) -->
         <meta name="twitter:card" content="summary_large_image" />
         <meta name="twitter:title" content="CrootSS: CSS Mobile Friendly Responsive Component and Template" />
         <meta name="twitter:description" content="CSS Mobile Friendly Responsive Component and Template" />
         <meta name="twitter:image" content="https://www.do.my.id/crootss.jpeg" />
        
     </head>
     <body>
     </body>
     </html>
    
  2. Pastikan terdapat robots.txt
    User-agent: *
    Allow: /
    Sitemap: https://alamat.github.io/sitemap.xml
    
  3. Pastikan terdapat sitemap.xml
    <?xml version="1.0" encoding="UTF-8"?>
     <urlset
         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
                 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    
     <url>
     <loc>https://www.bukupedia.co.id/</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>1.00</priority>
     </url>
     <url>
     <loc>https://katalog.bukupedia.co.id/</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>0.80</priority>
     </url>
     <url>
     <loc>https://penulis.bukupedia.co.id/</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>0.80</priority>
     </url>
     <url>
     <loc>https://www.bukupedia.co.id/p/layanan.html</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>0.80</priority>
     </url>
    
     </urlset>
    
  4. Pastikan terlebih dahulu anda mengunggah file favicon.ico
  5. Pastikan anda membuat file 404.html

Login Menggunakan WhatsAuth

API whatsauth dapat digunakan untuk pengembangan implementasi SSO, login menggunakan QR dan Google SignIn. Buat repo baru yang berisi:

  1. index.html : File html utama yang memanggil js qr dan gsi
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>WhatsAuth | Free WhatsApp API OTP Notif Broadcast Gratis</title>
        <link href="style.css" rel="stylesheet">
    	<script src="main.js" type="module"></script>
    </head>
    <body>
     <div id="hasphonenumber" class="w-full h-screen bg-blue-100 flex items-center justify-center">
         <div class="w-96 bg-white rounded-xl">
             <p class="font-bold text-center mb-4" id="useracclog">Tap/Scan dengan <a href="./camwab.jpg" target="_blank">Camera WA</a></p>
             <div class="flex justify-center mt-2 mb-4" id="whatsauthqr">
                 <img src="loading.svg">
             </div>
             <p class="font-bold text-center mb-4" id="whatsauthcounter">counter</p>
             <p class="font-bold text-center mb-4" id="logs"><a href="https://wa.my.id">WhatsAuth Free WhatsApp Notif, OTP, API Gateway Gratis</a></p>
         </div>
     </div>
    </body>
    </html>   
    
  2. main.js : pengaturan login menggunakan crootjs
    import {qrController,deleteCookie,appendGoogleSignin} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/auth.js";
    import { wauthparam } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/config.js";
       
    wauthparam.auth_ws="d3NzOi8vYXBpLndhLm15LmlkL3dzL3doYXRzYXV0aC9wdWJsaWM=";
    wauthparam.keyword="aHR0cHM6Ly93YS5tZS82MjgzMTMxODk1MDAwP3RleHQ9d2g0dDVhdXRoMA==";
    wauthparam.tokencookiehourslifetime=18;
    wauthparam.redirect ="/auth"
    deleteCookie(wauthparam.tokencookiename);
    qrController(wauthparam);
       
    const url="https://asia-southeast2-awangga.cloudfunctions.net/bukupedia/auth/users";
    
    const client_id="239713755402-4hr2cva377m43rsqs2dk0c7f7cktfeph.apps.googleusercontent.com";
    
    // Panggil fungsi untuk menambahkan elemen
    appendGoogleSignin(client_id,url);
    

    Ubah variabel wauthparam.keyword disesuaikan dengan nomor yang di daftarkan di WhatsAuth. Gunakan Base64 Decode dan Encode dengan melakukan update dari string keyword diatas untuk di update. image

Untuk file-file tambahan:

  1. style.css
  2. loading.svg

Jangan lupa untuk menambahkan domainnya di Console APIs&Services - Client ID for Web application
image

Repo Auth

Untuk melakukan otorisasi antara frontend dan backend maka diperlukan satu repo tambahan bernama auth(ada di settingan qr.js yaitu /auth). Pada file index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="index.js" type="module"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Selamat Datang di Naskah Bukupedia</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="scene">
        <div class="shadow"></div>
        <div class="jumper">
          <div class="spinner">
            <div class="scaler">
              <div class="loader">
                <div class="cuboid">
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      
      </div>
</body>
</html>

Pada file index.js

import {getCookie} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/cookie.js";
import {getJSON} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.js";
import {redirect} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/url.js";

if (getCookie("login")){
    getJSON("https://asia-southeast2-awangga.cloudfunctions.net/florka/data/user",responseFunction,"login",getCookie("login"));
}else{
    redirect("/login");
}


function responseFunction(result){
    console.log(result);
    if (result.status === 200){
        redirect("/dashboard");
    }else{
        redirect("/daftar");
    }
}

dan file style.css

Integrasi WhatsAuth dengan JSCroot dan GOCroot

Tutorial Web

Untuk pengembangan sendiri. Silahkan buka Panduan Deployment WebHook