@nsp-labs/agnostic-sdk 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 ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@nsp-labs/agnostic-sdk` are recorded here.
4
+
5
+ This package follows the Runtime SDK release policy in
6
+ `docs/shared/runtime-sdk-release.md`. Every published package version must move
7
+ entries out of `Unreleased`, include the runtime API/schema compatibility note,
8
+ and pass the runtime OpenAPI schema check.
9
+
10
+ ## Unreleased
11
+
12
+ - Prepared npm package metadata for `@nsp-labs/agnostic-sdk`.
13
+ - Added CI coverage for generated Runtime SDK OpenAPI schema drift.
14
+ - Documented Runtime SDK semver, changelog, and browser-token security policy.
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Newsmart Pro
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # @nsp-labs/agnostic-sdk
2
+
3
+ TypeScript Runtime SDK for server-side code running inside an Agnostic project
4
+ runtime or trusted local scripts. It is scoped to one `projectId +
5
+ environment + runtime token` and does not expose control-plane resources.
6
+
7
+ ```bash
8
+ npm install @nsp-labs/agnostic-sdk
9
+ ```
10
+
11
+ ## Context
12
+
13
+ Inside managed runtime, context is resolved automatically:
14
+
15
+ ```text
16
+ AGNOSTIC_API_URL=
17
+ AGNOSTIC_PROJECT_ID=
18
+ AGNOSTIC_ENVIRONMENT=
19
+ AGNOSTIC_RUNTIME_TOKEN=
20
+ ```
21
+
22
+ Local scripts can pass the same context explicitly:
23
+
24
+ ```ts
25
+ import { createAgnosticRuntime } from '@nsp-labs/agnostic-sdk';
26
+
27
+ const agnostic = createAgnosticRuntime({
28
+ apiUrl: 'https://api.agn0.ru',
29
+ projectId: 'proj_123',
30
+ environment: 'production',
31
+ token: process.env.AGNOSTIC_RUNTIME_TOKEN,
32
+ });
33
+ ```
34
+
35
+ Runtime tokens are server-side credentials. Do not put
36
+ `AGNOSTIC_RUNTIME_TOKEN` in browser, mobile, Vite, or static frontend bundles.
37
+
38
+ ## App Auth
39
+
40
+ Use `agnostic.auth.requireSession(request)` in an application backend to verify
41
+ the incoming App Auth session through the runtime helper:
42
+
43
+ ```ts
44
+ const session = await agnostic.auth.requireSession(request);
45
+
46
+ await agnostic.events.publish(
47
+ 'order.updated',
48
+ { orderId: 'order_123' },
49
+ { actor: session.actor },
50
+ );
51
+ ```
52
+
53
+ The helper extracts `Authorization: Bearer <app-session>` or an
54
+ `agnostic_app_session_*` cookie, then calls
55
+ `/api/v1/runtime/app-auth/session/verify` with the server-side runtime token.
56
+ It returns sanitized user/session claims and an `app_user` actor for audit
57
+ metadata. `agnostic.auth.getUser(userId)` reads sanitized App Auth user claims
58
+ for the same runtime project.
59
+
60
+ ## Data
61
+
62
+ ```ts
63
+ const orders = await agnostic.data.table('orders').records.list({
64
+ filter: { status: 'paid' },
65
+ limit: 50,
66
+ });
67
+
68
+ const created = await agnostic.data.table('orders').records.create({
69
+ values: {
70
+ customerId: 'cust_123',
71
+ status: 'paid',
72
+ },
73
+ });
74
+
75
+ await agnostic.data.table('orders').records.update(created.id, {
76
+ status: 'fulfilled',
77
+ });
78
+
79
+ await agnostic.data.table('orders').records.delete(created.id);
80
+ ```
81
+
82
+ ## Events
83
+
84
+ ```ts
85
+ await agnostic.events.publish('order.fulfilled', {
86
+ orderId: 'order_123',
87
+ customerId: 'cust_123',
88
+ });
89
+
90
+ await agnostic.events.publishBatch('order.fulfilled', [
91
+ { payload: { orderId: 'order_123' } },
92
+ { payload: { orderId: 'order_124' } },
93
+ ]);
94
+ ```
95
+
96
+ ## Jobs
97
+
98
+ ```ts
99
+ await agnostic.jobs.enqueue(
100
+ 'send-receipt',
101
+ { orderId: 'order_123' },
102
+ { delaySeconds: 30 },
103
+ );
104
+ ```
105
+
106
+ ## Gateway
107
+
108
+ ```ts
109
+ const result = await agnostic.gateway.call('billing/create-invoice', {
110
+ orderId: 'order_123',
111
+ });
112
+
113
+ if (result.status >= 400) {
114
+ throw new Error('Gateway route failed');
115
+ }
116
+ ```
117
+
118
+ ## Workflows
119
+
120
+ ```ts
121
+ const run = await agnostic.workflows.start('send-receipt', {
122
+ orderId: 'order_123',
123
+ });
124
+
125
+ const finished = await agnostic.workflowRuns.wait(run.id, {
126
+ timeoutMs: 30_000,
127
+ });
128
+ ```
129
+
130
+ ## Actor Metadata
131
+
132
+ After an application backend has verified its App Auth session and business
133
+ guardrails, it can pass actor metadata for audit context:
134
+
135
+ ```ts
136
+ await agnostic.events.publish(
137
+ 'order.updated',
138
+ { orderId: 'order_123' },
139
+ {
140
+ actor: {
141
+ type: 'app_user',
142
+ id: 'app_user_123',
143
+ scopes: ['orders:write'],
144
+ },
145
+ },
146
+ );
147
+ ```
148
+
149
+ Allowed actor types are `app_user`, `platform_user`, `runtime`, and `system`.
150
+ Actor metadata is not authorization input for Runtime SDK capabilities.
151
+
152
+ ## Errors
153
+
154
+ Runtime API failures throw `AgnosticRuntimeError`:
155
+
156
+ ```ts
157
+ import { AgnosticRuntimeError } from '@nsp-labs/agnostic-sdk';
158
+
159
+ try {
160
+ await agnostic.data.table('orders').records.list();
161
+ } catch (error) {
162
+ if (error instanceof AgnosticRuntimeError) {
163
+ console.error(error.status, error.code, error.message, error.details);
164
+ }
165
+ }
166
+ ```
167
+
168
+ ## OpenAPI Layer
169
+
170
+ `src/generated/openapi.ts` is generated from `/api/docs-json` after filtering to
171
+ `/api/v1/runtime/*` paths:
172
+
173
+ ```bash
174
+ npm run sdk:gen
175
+ ```
176
+
177
+ CI validates the committed generated layer with:
178
+
179
+ ```bash
180
+ npm run sdk:check
181
+ ```
182
+
183
+ The generated client is internal. Public code should use
184
+ `createAgnosticRuntime` and the ergonomic namespaces above.
185
+
186
+ ## Versioning And Changelog
187
+
188
+ `@nsp-labs/agnostic-sdk` follows semver with the Runtime SDK API contract. Breaking
189
+ runtime endpoint or public SDK changes require a major version;
190
+ backwards-compatible namespaces, methods, options, or response fields are minor
191
+ changes; bug fixes and generated type refreshes without API changes are patch
192
+ changes.
193
+
194
+ Release notes are tracked in `CHANGELOG.md`. Do not publish a package version
195
+ unless the changelog is updated and `npm run sdk:check` passes.
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@nsp-labs/agnostic-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Server-side Runtime SDK for Agnostic project services, workers, automations, and trusted local scripts.",
5
+ "license": "ISC",
6
+ "type": "commonjs",
7
+ "main": "./src/index.js",
8
+ "types": "./src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.d.ts",
12
+ "require": "./src/index.js",
13
+ "default": "./src/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "src/**/*.js",
18
+ "src/**/*.d.ts",
19
+ "!src/**/*.js.map",
20
+ "README.md",
21
+ "CHANGELOG.md",
22
+ "LICENSE"
23
+ ],
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=18.18"
27
+ },
28
+ "keywords": [
29
+ "agnostic",
30
+ "runtime-sdk",
31
+ "server-side",
32
+ "workflow",
33
+ "data"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "ssh://ssh.sourcecraft.dev/newsmartpro/nsplabs-agnostic-core.git",
38
+ "directory": "packages/sdk-js"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "openapi-fetch": "^0.17.0",
45
+ "tslib": "^2.3.0"
46
+ }
47
+ }