@winche-technologies/admin 0.0.0-stage → 3.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Ehsan Rashidi
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.md CHANGED
@@ -1,3 +1,62 @@
1
- # Temporary Holding Version
1
+ # Winche admin TypeScript SDK (`@winche-technologies/admin`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Winche project's data — documents, files, the app's users, assets, and calling functions — with one API wherever it
4
+ runs. Published as `@winche-technologies/admin`, imported as `@winche/admin` (an alias):
5
+
6
+ ```sh
7
+ npm install @winche/admin@npm:@winche-technologies/admin # Node, bundlers
8
+ ```
9
+
10
+ ```json
11
+ // deno.json (functions)
12
+ { "imports": { "@winche/admin": "npm:@winche-technologies/admin@^3" } }
13
+ ```
14
+
15
+ Where it runs:
16
+
17
+ | Where | Acts as | Limited by |
18
+ | --- | --- | --- |
19
+ | Functions (`import … from "@winche/admin"`) | the server | nothing (access rules don't apply) |
20
+ | Console pages (the console resolves `@winche/admin`) | the person who opened the page | their role in the project |
21
+ | Anywhere else (`initializeAdmin`) | the token's account | its role in the project |
22
+
23
+ ```ts
24
+ import { initializeAdmin, FieldValue } from "@winche/admin";
25
+
26
+ const admin = initializeAdmin({ server: "https://winche.example.com", project: "clinic", token: process.env.WINCHE_TOKEN! });
27
+ await admin.documents.doc("wards/a").update({ visits: FieldValue.increment(1) });
28
+ const report = await admin.files.child("reports/a.pdf").getData();
29
+ ```
30
+
31
+ Roles: a viewer reads; a member also writes documents, files and the app's users; an admin may also call functions.
32
+
33
+ `as(user)` gives the same API acting as one of the app's users: documents and files calls are checked against the
34
+ project's access rules for them, as if the app had made them; `functions.call` passes them as the caller.
35
+
36
+ ```ts
37
+ import { callable } from "@winche/functions";
38
+ import { as } from "@winche/admin";
39
+
40
+ export const leave = callable(async (data: { ward: string }, ctx) => {
41
+ await as(ctx.caller!).documents.doc(`wards/${data.ward}/members/${ctx.caller!.uid}`).delete(); // the rules decide
42
+ });
43
+ ```
44
+
45
+ References (`doc`, `collection`, `child`, `user`) and the snapshots their reads return read like the Dart SDKs. See
46
+ Winche.Functions' README for the whole API.
47
+
48
+ ## How it's used
49
+
50
+ - **Functions:** Winche.Functions carries a pinned copy of `src/admin.ts` (its `scripts/update-admin-sdk.sh`) and gives
51
+ it to every deployment as `@winche/admin`.
52
+ - **Console pages:** Winche Server serves the same copy, bundled for browsers, beside each page.
53
+ - **Other servers:** this npm package.
54
+
55
+ ## Develop
56
+
57
+ `src/admin.ts` is the only source. `npm run build` (Deno and Node) makes `dist/`; `npm test` builds and runs the Node
58
+ test.
59
+
60
+ ## License
61
+
62
+ MIT (`LICENSE`).