@tacoshell/sdk 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/LICENSE +28 -0
- package/README.md +10 -2
- package/package.json +36 -4
- package/src/assets.d.ts +2 -0
- package/src/index.ts +185 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Taco Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ryanrutan. All rights reserved.
|
|
4
|
+
|
|
5
|
+
The software in this repository and in the published packages @tacoshell/sdk,
|
|
6
|
+
@tacoshell/shell and @tacoshell/cli (the "Software") is licensed, not sold.
|
|
7
|
+
|
|
8
|
+
1. Permitted use. You may install the Software and use it to develop, build,
|
|
9
|
+
test, package and distribute your own applications and extensions, including
|
|
10
|
+
the Software's runtime as it is built into those applications. You may also
|
|
11
|
+
read the source code, and modify it for your own use (including your own
|
|
12
|
+
internal forks) to learn from it, debug your applications or adapt it to
|
|
13
|
+
your needs.
|
|
14
|
+
|
|
15
|
+
2. Restrictions. Except as permitted above or by law, you may not: (a) publish
|
|
16
|
+
or distribute the Software or your modified versions of it on their own, or
|
|
17
|
+
as part of any framework, SDK, tool or competing product; (b) sublicense,
|
|
18
|
+
sell, rent or lease the Software; (c) remove or alter any copyright or
|
|
19
|
+
license notice.
|
|
20
|
+
|
|
21
|
+
3. Ownership. The author retains all right, title and interest in the Software.
|
|
22
|
+
No rights are granted other than those expressly stated here.
|
|
23
|
+
|
|
24
|
+
4. No warranty. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
25
|
+
EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM,
|
|
26
|
+
DAMAGES OR OTHER LIABILITY ARISING FROM THE SOFTWARE OR ITS USE.
|
|
27
|
+
|
|
28
|
+
5. Termination. This license ends automatically if you breach it.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tacoshell/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The only import Taco **module code** needs: types and helpers for views, services (`defineService`), dataset routines (`defineRoutine`), topics, notifications, search resolvers and the `Framework` object a view receives.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { defineService, type ViewProps } from '@tacoshell/sdk';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Ships TypeScript source (the app build compiles it). You normally don't install this by hand: `taco-cli` brings it, and generated modules type-check against it through `tsconfig.json` paths.
|
|
10
|
+
|
|
11
|
+
Part of the Taco framework monorepo: see the repository root and `dev/GETTING-STARTED.md`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tacoshell/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The only import Taco module code needs: types and helpers for views, services, topics, search and notifications.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"taco",
|
|
7
|
+
"chrome-extension",
|
|
8
|
+
"mv3",
|
|
9
|
+
"sdk"
|
|
10
|
+
],
|
|
11
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/ryanrutan/tacoshell.git",
|
|
15
|
+
"directory": "packages/sdk"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/ryanrutan/tacoshell#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/ryanrutan/tacoshell/issues"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./src/index.ts",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org",
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/assets.d.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// @tacoshell/sdk: the only framework import module code needs (TECH-GUIDANCE §6).
|
|
2
|
+
import { useEffect, useSyncExternalStore, type ReactNode } from 'react';
|
|
3
|
+
// Generated taco.gen.ts files declare structurally identical ref types inline, so a module also type-checks before this package is installed.
|
|
4
|
+
|
|
5
|
+
// ── References (built by generated code; ADR-020) ────────────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
export interface TopicRef<Req, Res> {
|
|
8
|
+
readonly kind: 'topic';
|
|
9
|
+
readonly module: string;
|
|
10
|
+
/** `service:<type>/<name>`, `view:<name>`, `dataset:<name>` or `template:<name>`. */
|
|
11
|
+
readonly component: string;
|
|
12
|
+
readonly topic: string;
|
|
13
|
+
build(payload: Req): Message<Req, Res>;
|
|
14
|
+
}
|
|
15
|
+
export interface Message<Req, Res> { readonly topic: TopicRef<Req, Res>; readonly payload: Req }
|
|
16
|
+
/** `C` is the context the view accepts (declared in its manifest's `context`), so `showView` is type-checked (ADR-052). */
|
|
17
|
+
export interface ViewRef<C = Context> { readonly kind: 'view'; readonly module: string; readonly component: string; readonly __context?: C }
|
|
18
|
+
export interface NotificationPayload { title?: string; message: string; data?: Record<string, unknown>; view?: ViewRef; context?: Record<string, unknown>; key?: string }
|
|
19
|
+
export interface NotificationRef {
|
|
20
|
+
readonly kind: 'notification';
|
|
21
|
+
readonly module: string;
|
|
22
|
+
readonly id: string;
|
|
23
|
+
build(payload: NotificationPayload): NotificationMessage;
|
|
24
|
+
}
|
|
25
|
+
export interface NotificationMessage { readonly notification: NotificationRef; readonly payload: NotificationPayload }
|
|
26
|
+
|
|
27
|
+
export function topic<Req, Res>(module: string, component: string, name: string): TopicRef<Req, Res> {
|
|
28
|
+
const ref: TopicRef<Req, Res> = { kind: 'topic', module, component, topic: name, build: (payload: Req) => ({ topic: ref, payload }) };
|
|
29
|
+
return ref;
|
|
30
|
+
}
|
|
31
|
+
export const view = <C = Context>(module: string, component: string): ViewRef<C> => ({ kind: 'view', module, component });
|
|
32
|
+
export function notification(module: string, id: string): NotificationRef {
|
|
33
|
+
const ref: NotificationRef = { kind: 'notification', module, id, build: (payload) => ({ notification: ref, payload }) };
|
|
34
|
+
return ref;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ── Logging (ADR-027, ADR-040) ─────────────────────────────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
40
|
+
export const LOG_LEVELS: readonly LogLevel[] = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
|
|
41
|
+
/** Every call returns immediately; nothing waits for the Activity Log (ADR-027). `data` is redacted before storage. */
|
|
42
|
+
export type Logger = Record<LogLevel, (message: string, data?: unknown) => void>;
|
|
43
|
+
|
|
44
|
+
// ── The framework API a view gets (ADR-015, ADR-036) ──────────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
export type SendError = 'unavailable' | 'locked' | 'denied' | 'invalid' | 'timeout' | 'failed';
|
|
47
|
+
export type SendResult<Res> = { ok: true; value: Res } | { ok: false; error: SendError; message: string };
|
|
48
|
+
export type Context = Record<string, unknown>;
|
|
49
|
+
|
|
50
|
+
/** An observable value; read it in React with `useStoreValue`. */
|
|
51
|
+
export interface Store<T> { get(): T; subscribe(listener: () => void): () => void }
|
|
52
|
+
|
|
53
|
+
/** Shared by every component on the current page: the view and the panels in its slots (ADR-053). */
|
|
54
|
+
export interface PageContext extends Store<Context> {
|
|
55
|
+
/** Merge values; every component reading the page context re-renders. */
|
|
56
|
+
set(patch: Context): void;
|
|
57
|
+
/** Ask every component on the page to reload its data (e.g. after a write). */
|
|
58
|
+
refresh(reason?: string): void;
|
|
59
|
+
onRefresh(listener: (reason?: string) => void): () => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** An entry in the 3rd-level bar's Tools menu, which shows only while the page has tools (ADR-051). */
|
|
63
|
+
export interface Tool {
|
|
64
|
+
id: string;
|
|
65
|
+
label: string;
|
|
66
|
+
/** Font Awesome classes ("fa-solid fa-copy"; the framework bundles Font Awesome Free) or a short text glyph. */
|
|
67
|
+
icon?: string;
|
|
68
|
+
run(): void | Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface Framework {
|
|
72
|
+
/** Request/response to a topic (a service operation, a dataset query…). Never throws; check `ok`. */
|
|
73
|
+
send<Req, Res>(message: Message<Req, Res>): Promise<SendResult<Res>>;
|
|
74
|
+
/** Fire an event topic to every subscriber. */
|
|
75
|
+
publish<Req>(message: Message<Req, unknown>): void;
|
|
76
|
+
subscribe<Req>(topic: TopicRef<Req, unknown>, handler: (payload: Req) => void): () => void;
|
|
77
|
+
/** Navigate with state. Resolves false if a guard refused or the context doesn't match the view's declaration (ADR-036, ADR-052). */
|
|
78
|
+
showView<C>(view: ViewRef<C>, context?: C): Promise<boolean>;
|
|
79
|
+
/** The latest context this view was given: at open time, then any later hand-off while it is open (ADR-052). */
|
|
80
|
+
viewContext: Store<Context | undefined>;
|
|
81
|
+
/** State shared by every component on this page (ADR-053). */
|
|
82
|
+
page: PageContext;
|
|
83
|
+
/** Add to the 3rd-level bar's Tools menu for as long as this page is open; returns a function that removes it. */
|
|
84
|
+
tools: { add(tool: Tool): () => void };
|
|
85
|
+
/** Renders the panels other modules contribute to one of this view's declared slots (ADR-053). */
|
|
86
|
+
slot(name: string): ReactNode;
|
|
87
|
+
/** Send a declared notification (ADR-028, ADR-041). */
|
|
88
|
+
notify(message: NotificationMessage): void;
|
|
89
|
+
log: Logger;
|
|
90
|
+
/** Navigation guards; each returns a function that removes the guard. */
|
|
91
|
+
guard: {
|
|
92
|
+
/** Refuse every navigation while held (e.g. a bulk run). */
|
|
93
|
+
block(reason: string): () => void;
|
|
94
|
+
/** Ask Stay / Leave while `isDirty()` is true. */
|
|
95
|
+
unsaved(isDirty: () => boolean): () => void;
|
|
96
|
+
};
|
|
97
|
+
/** Encrypted storage scoped to this module (ADR-031). Waits for the unlock prompt while the vault is locked. */
|
|
98
|
+
storage: { get<T>(key: string): Promise<T | undefined>; set(key: string, value: unknown): Promise<void>; remove(key: string): Promise<void> };
|
|
99
|
+
/** Receive context handed over by `showView` while this view is open (ADR-036). Prefer `useViewContext`. */
|
|
100
|
+
setContextHandler(handler: (context: Context) => void): void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ── React hooks ────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
export const useStoreValue = <T,>(store: Store<T>): T => useSyncExternalStore(store.subscribe, store.get);
|
|
106
|
+
/** The context this view was opened with, updated live when another view hands it a new one. */
|
|
107
|
+
export const useViewContext = <C = Context,>(framework: Framework) => useStoreValue(framework.viewContext) as C | undefined;
|
|
108
|
+
/** The page's shared state; re-renders when any component on the page changes it. */
|
|
109
|
+
export const usePageContext = <C = Context,>(framework: Framework) => useStoreValue(framework.page) as C;
|
|
110
|
+
/** Runs `reload` whenever a component on the page calls `framework.page.refresh()` or the user presses Refresh in the 3rd-level bar. A page with no listener is re-mounted by that button instead. */
|
|
111
|
+
export function usePageRefresh(framework: Framework, reload: (reason?: string) => void) {
|
|
112
|
+
useEffect(() => framework.page.onRefresh(reload), [framework, reload]);
|
|
113
|
+
}
|
|
114
|
+
/** Adds a Tools menu entry while the component is mounted. */
|
|
115
|
+
export function useTool(framework: Framework, tool: Tool | null) {
|
|
116
|
+
useEffect(() => (tool ? framework.tools.add(tool) : undefined), [framework, tool?.id]);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A panel contributed into another view's slot (ADR-053). It reads and writes the host page's context through `framework.page`. */
|
|
120
|
+
export interface PanelProps { framework: Framework; slot: string }
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A card: a sub-feature any page can show. It is wired to page-context entries (manifest › cards.<name>.context), not to a page: it appears on every view
|
|
124
|
+
* whose page context has them and works the same on each. `context` holds just those entries and updates live; `framework.page` is the host page's.
|
|
125
|
+
*/
|
|
126
|
+
export interface CardProps<C = Context> { framework: Framework; context: C }
|
|
127
|
+
|
|
128
|
+
export interface ViewProps {
|
|
129
|
+
framework: Framework;
|
|
130
|
+
/** Context the view was opened with, if any. Later contexts arrive through `setContextHandler`. */
|
|
131
|
+
context?: Context;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ── Services (ADR-004, ADR-023) ────────────────────────────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
export interface ServiceContext {
|
|
137
|
+
instance: { module: string; type: string; name: string };
|
|
138
|
+
/** Non-secret field values from Settings → Services. */
|
|
139
|
+
config: Record<string, string>;
|
|
140
|
+
authMode: 'session' | 'apikey' | 'basic' | 'oauth';
|
|
141
|
+
/** A secret field from the vault. Waits for the unlock prompt while the vault is locked. */
|
|
142
|
+
secret(field: string): Promise<string>;
|
|
143
|
+
/**
|
|
144
|
+
* https-only fetch limited to the service's declared hosts, with the auth mode applied (cookies for session, headers otherwise)
|
|
145
|
+
* and one redacted debug log line per attempt (ADR-040). `json` sets a JSON body.
|
|
146
|
+
*/
|
|
147
|
+
fetch(url: string, init?: RequestInit & { json?: unknown }): Promise<Response>;
|
|
148
|
+
log: Logger;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** One thing a search term resolved to. `context` is the connector's own description of it (e.g. `{ slug, email }`); Quick Actions receive it. */
|
|
152
|
+
export interface SearchResult { id: string; label: string; detail?: string; context: Context }
|
|
153
|
+
|
|
154
|
+
export interface ServiceImpl {
|
|
155
|
+
/**
|
|
156
|
+
* Opt-in search (declare `resolver` on the service in taco.module.json): turn the header search term into zero or more contexts.
|
|
157
|
+
* One result is used as the context without asking; several are listed for the user to pick. Views then offer Quick Action tiles for it.
|
|
158
|
+
*/
|
|
159
|
+
resolve?(term: string, ctx: ServiceContext): Promise<SearchResult[]>;
|
|
160
|
+
/**
|
|
161
|
+
* For "Current Session" sign-in: is the user signed in to the service's site right now? Shown in the header's Sessions menu.
|
|
162
|
+
* Return `{ active: false }` (or throw) when there is no session. If you leave this out, a passing `test()` counts as an active session.
|
|
163
|
+
*/
|
|
164
|
+
session?(ctx: ServiceContext): Promise<{ active: boolean; who?: string; detail?: string }>;
|
|
165
|
+
/** Called by Test on the service page; throw to fail. Return `who` to show "Connected as …". */
|
|
166
|
+
test?(ctx: ServiceContext): Promise<{ who?: string } | void>;
|
|
167
|
+
/** Handlers for the service's custom topics (declared in taco.module.json). */
|
|
168
|
+
topics?: Record<string, (payload: any, ctx: ServiceContext) => Promise<unknown>>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const defineService = (impl: ServiceImpl): ServiceImpl => impl;
|
|
172
|
+
|
|
173
|
+
// ── Dataset routines (ADR-043): how a refreshable dataset produces its rows ─────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
export interface RoutineContext {
|
|
176
|
+
/** The module's framework instance: call services through `send` (uses / own constants), like any view. */
|
|
177
|
+
framework: Framework;
|
|
178
|
+
log: Logger;
|
|
179
|
+
previous: { rows: number; updatedAt?: string };
|
|
180
|
+
}
|
|
181
|
+
export interface Routine {
|
|
182
|
+
/** Returns every row (a Full Load). The stored data is replaced only when this succeeds, so a failed refresh loses nothing. */
|
|
183
|
+
run(ctx: RoutineContext): Promise<{ rows: Record<string, unknown>[]; columns?: string[] }>;
|
|
184
|
+
}
|
|
185
|
+
export const defineRoutine = (routine: Routine): Routine => routine;
|