@saplings/sdk 0.0.0-stage → 0.17.2
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 +32 -0
- package/LICENSE +21 -0
- package/README.md +60 -2
- package/dist/access.d.ts +3 -0
- package/dist/access.js +3 -0
- package/dist/access.js.map +1 -0
- package/dist/accounts.d.ts +3 -0
- package/dist/accounts.js +3 -0
- package/dist/accounts.js.map +1 -0
- package/dist/analytics.d.ts +45 -0
- package/dist/analytics.js +129 -0
- package/dist/analytics.js.map +1 -0
- package/dist/audit.d.ts +21 -0
- package/dist/audit.js +36 -0
- package/dist/audit.js.map +1 -0
- package/dist/automation.d.ts +49 -0
- package/dist/automation.js +210 -0
- package/dist/automation.js.map +1 -0
- package/dist/billing-policy.d.ts +15 -0
- package/dist/billing-policy.js +17 -0
- package/dist/billing-policy.js.map +1 -0
- package/dist/billing.d.ts +53 -0
- package/dist/billing.js +118 -0
- package/dist/billing.js.map +1 -0
- package/dist/business-workflows.d.ts +39 -0
- package/dist/business-workflows.js +137 -0
- package/dist/business-workflows.js.map +1 -0
- package/dist/capabilities.d.ts +49 -0
- package/dist/capabilities.js +78 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/cashfree.d.ts +71 -0
- package/dist/cashfree.js +241 -0
- package/dist/cashfree.js.map +1 -0
- package/dist/commerce.d.ts +21 -0
- package/dist/commerce.js +198 -0
- package/dist/commerce.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +177 -0
- package/dist/config.js.map +1 -0
- package/dist/control-plane.d.ts +129 -0
- package/dist/control-plane.js +314 -0
- package/dist/control-plane.js.map +1 -0
- package/dist/data.d.ts +58 -0
- package/dist/data.js +214 -0
- package/dist/data.js.map +1 -0
- package/dist/domain-policy.d.ts +36 -0
- package/dist/domain-policy.js +114 -0
- package/dist/domain-policy.js.map +1 -0
- package/dist/feature-types.d.ts +187 -0
- package/dist/feature-types.js +2 -0
- package/dist/feature-types.js.map +1 -0
- package/dist/federation.d.ts +66 -0
- package/dist/federation.js +162 -0
- package/dist/federation.js.map +1 -0
- package/dist/flags.d.ts +27 -0
- package/dist/flags.js +52 -0
- package/dist/flags.js.map +1 -0
- package/dist/governance.d.ts +45 -0
- package/dist/governance.js +128 -0
- package/dist/governance.js.map +1 -0
- package/dist/http-idempotency.d.ts +22 -0
- package/dist/http-idempotency.js +42 -0
- package/dist/http-idempotency.js.map +1 -0
- package/dist/http.d.ts +2 -0
- package/dist/http.js +28 -0
- package/dist/http.js.map +1 -0
- package/dist/identity.d.ts +3 -0
- package/dist/identity.js +3 -0
- package/dist/identity.js.map +1 -0
- package/dist/impersonation.d.ts +2 -0
- package/dist/impersonation.js +3 -0
- package/dist/impersonation.js.map +1 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +519 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations.d.ts +114 -0
- package/dist/integrations.js +358 -0
- package/dist/integrations.js.map +1 -0
- package/dist/jobs.d.ts +29 -0
- package/dist/jobs.js +77 -0
- package/dist/jobs.js.map +1 -0
- package/dist/media.d.ts +18 -0
- package/dist/media.js +48 -0
- package/dist/media.js.map +1 -0
- package/dist/offboarding.d.ts +43 -0
- package/dist/offboarding.js +140 -0
- package/dist/offboarding.js.map +1 -0
- package/dist/operations.d.ts +105 -0
- package/dist/operations.js +286 -0
- package/dist/operations.js.map +1 -0
- package/dist/primitives.d.ts +26 -0
- package/dist/primitives.js +119 -0
- package/dist/primitives.js.map +1 -0
- package/dist/provider-operations.d.ts +43 -0
- package/dist/provider-operations.js +143 -0
- package/dist/provider-operations.js.map +1 -0
- package/dist/provider-workflow.d.ts +33 -0
- package/dist/provider-workflow.js +111 -0
- package/dist/provider-workflow.js.map +1 -0
- package/dist/providers.d.ts +42 -0
- package/dist/providers.js +168 -0
- package/dist/providers.js.map +1 -0
- package/dist/quality-config.d.ts +50 -0
- package/dist/quality-config.js +2 -0
- package/dist/quality-config.js.map +1 -0
- package/dist/razorpay-webhook.d.ts +38 -0
- package/dist/razorpay-webhook.js +106 -0
- package/dist/razorpay-webhook.js.map +1 -0
- package/dist/recurring.d.ts +53 -0
- package/dist/recurring.js +241 -0
- package/dist/recurring.js.map +1 -0
- package/dist/registry.d.ts +58 -0
- package/dist/registry.js +839 -0
- package/dist/registry.js.map +1 -0
- package/dist/reliability.d.ts +45 -0
- package/dist/reliability.js +147 -0
- package/dist/reliability.js.map +1 -0
- package/dist/resources.d.ts +19 -0
- package/dist/resources.js +90 -0
- package/dist/resources.js.map +1 -0
- package/dist/security-state.d.ts +14 -0
- package/dist/security-state.js +39 -0
- package/dist/security-state.js.map +1 -0
- package/dist/storage.d.ts +54 -0
- package/dist/storage.js +100 -0
- package/dist/storage.js.map +1 -0
- package/dist/store.d.ts +21 -0
- package/dist/store.js +110 -0
- package/dist/store.js.map +1 -0
- package/dist/stripe-payment.d.ts +21 -0
- package/dist/stripe-payment.js +132 -0
- package/dist/stripe-payment.js.map +1 -0
- package/dist/stripe-recurring.d.ts +58 -0
- package/dist/stripe-recurring.js +226 -0
- package/dist/stripe-recurring.js.map +1 -0
- package/dist/totp.d.ts +2 -0
- package/dist/totp.js +3 -0
- package/dist/totp.js.map +1 -0
- package/dist/transactional-processing.d.ts +27 -0
- package/dist/transactional-processing.js +125 -0
- package/dist/transactional-processing.js.map +1 -0
- package/dist/types.d.ts +367 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/valkey.d.ts +18 -0
- package/dist/valkey.js +22 -0
- package/dist/valkey.js.map +1 -0
- package/dist/worker.d.ts +28 -0
- package/dist/worker.js +201 -0
- package/dist/worker.js.map +1 -0
- package/package.json +34 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @saplings/sdk
|
|
2
|
+
|
|
3
|
+
## 0.17.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 886be53: Enforce the tenant freeze inside transactions for direct resource mutations and durable job admission. Paused tenants retain pending work and can resume after reactivation.
|
|
8
|
+
- 886be53: Publish onboarding guides, API summaries, and examples in each npm package.
|
|
9
|
+
|
|
10
|
+
Use the single sapling executable for catalog, scan, doctor, and quality commands. Install @saplings/cli and replace sapling-quality with sapling quality. Replace sapling-quality-legacy with sapling quality legacy.
|
|
11
|
+
- Updated dependencies [886be53]
|
|
12
|
+
- @saplings/catalog@0.17.2
|
|
13
|
+
- @saplings/harbor@0.17.2
|
|
14
|
+
- @saplings/kingsman@0.17.2
|
|
15
|
+
- @saplings/middleware@0.17.2
|
|
16
|
+
- @saplings/quality-contracts@0.17.2
|
|
17
|
+
- @saplings/realtime@0.17.2
|
|
18
|
+
- @saplings/security@0.17.2
|
|
19
|
+
|
|
20
|
+
## 0.17.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- cf8fe00: Prepare the reusable Sapling packages for their first release under the `@saplings` npm scope. Include package license notices and publish installable tarballs with resolved internal dependencies.
|
|
25
|
+
- Updated dependencies [cf8fe00]
|
|
26
|
+
- @saplings/catalog@0.17.1
|
|
27
|
+
- @saplings/harbor@0.17.1
|
|
28
|
+
- @saplings/kingsman@0.17.1
|
|
29
|
+
- @saplings/middleware@0.17.1
|
|
30
|
+
- @saplings/quality-contracts@0.17.1
|
|
31
|
+
- @saplings/realtime@0.17.1
|
|
32
|
+
- @saplings/security@0.17.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sapling Unified SDK contributors
|
|
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,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @saplings/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-side TypeScript SDK for multi-tenant applications. It combines tenant-scoped data, authorization, identity and gateway integration, storage, billing, events, and background jobs behind one configured instance.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Use Node.js 26.13.1 or newer in the Node.js 26 line. The SDK uses ESM and ships TypeScript declarations.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @saplings/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Create and read a project
|
|
14
|
+
|
|
15
|
+
Save this as `quickstart.mts` and run `node quickstart.mts`. The fixture uses an in-memory store and a server-created actor.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createSapling, defineSaplingConfig, type ActorContext } from '@saplings/sdk';
|
|
19
|
+
|
|
20
|
+
const sdk = createSapling(
|
|
21
|
+
defineSaplingConfig({ app: { id: 'my-app', environment: 'development' } }),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const actor: ActorContext = {
|
|
25
|
+
tenantId: 'demo-tenant',
|
|
26
|
+
actorId: 'demo-user',
|
|
27
|
+
permissions: ['projects:read', 'projects:write'],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const created = await sdk.projects.create(actor, { name: 'First project' });
|
|
31
|
+
console.log(await sdk.projects.get(actor, created.id));
|
|
32
|
+
console.log(await sdk.readiness());
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
For HTTP requests, derive the actor from a verified session or an authentication adapter. Keep tenant and permission decisions on the server. Use `sdk.authorize(actor, permission, resource)` for application-specific actions and translate `SaplingError` into the appropriate response for your framework.
|
|
36
|
+
|
|
37
|
+
## SDK signatures
|
|
38
|
+
|
|
39
|
+
| Entry point | Signature or result |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `defineSaplingConfig` | `<T extends SaplingConfig>(config: T): T` preserves the configuration's inferred type. |
|
|
42
|
+
| `createSapling` | `(config: SaplingConfig): SaplingSDK` creates the SDK instance. |
|
|
43
|
+
| `sdk.projects.create` | `(ctx: ActorContext, data: JsonRecord): Promise<ResourceRecord>` creates a tenant-scoped record. |
|
|
44
|
+
| `sdk.projects.get` | `(ctx: ActorContext, id: string): Promise<ResourceRecord \| undefined>` reads a record in the actor's tenant. |
|
|
45
|
+
| `sdk.projects.list` | `(ctx: ActorContext, options?: { limit?: number; offset?: number; filter?: JsonRecord }): Promise<ResourceRecord[]>` lists visible records. |
|
|
46
|
+
| `sdk.authorize` | `(ctx: ActorContext, permission: string, resource?: Record<string, unknown>)` checks access and throws when denied. |
|
|
47
|
+
| `sdk.invokeCapability` | `<I extends FeatureId>(ctx: ActorContext, id: I, action: FeatureAction<NoInfer<I>>, input?: JsonRecord)` invokes a catalog action. Provider results need application validation. |
|
|
48
|
+
| `sdk.featureManifest` | Lists registered feature actions. `sdk.getCapability(id)` and `sdk.listCapabilities()` expose catalog metadata. |
|
|
49
|
+
| `sdk.readiness` | Runs configured probes and reports a ready, degraded, or unready state. |
|
|
50
|
+
| `sdk.closeRealtime` | `(): Promise<void>` closes the configured realtime hub. |
|
|
51
|
+
|
|
52
|
+
`SaplingConfig` starts with `app.id` and `app.environment`. Supply infrastructure through `providers`, application policies through `services` and `access`, and verified context through `hooks.resolveRequestContext` or `providers.authentication`. The published `.d.ts` files and [SDK source](https://github.com/snrakshith/saplings/tree/main/packages/sdk/src) describe the remaining service methods.
|
|
53
|
+
|
|
54
|
+
## Prepare a deployment
|
|
55
|
+
|
|
56
|
+
- Inject a durable `providers.store` such as [the Drizzle adapter](https://www.npmjs.com/package/@saplings/adapter-drizzle). Apply the database migrations, run with a restricted database role, and verify tenant isolation.
|
|
57
|
+
- Wire providers for features your application enables. Test provider failures, webhook verification, retries, and idempotency using your deployment configuration.
|
|
58
|
+
- Use `sdk.defender.preflight()` before bounded request parsing and `sdk.middleware()` after parsing. Signed webhooks need access to the original request bytes.
|
|
59
|
+
- Register background handlers with `sdk.automation.register` and run `sdk.worker.run` in a worker with a trusted tenant context source and a shutdown signal.
|
|
60
|
+
|
|
61
|
+
See the [configuration reference](https://github.com/snrakshith/saplings/blob/main/docs/CONFIGURATION_REFERENCE.md), [Express starter](https://github.com/snrakshith/saplings/tree/main/examples/express-app), and [release validation guide](https://github.com/snrakshith/saplings/blob/main/docs/RELEASE_VALIDATION.md).
|
package/dist/access.d.ts
ADDED
package/dist/access.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ActorContext, JsonRecord, Store } from './types.js';
|
|
2
|
+
import type { Row } from './primitives.js';
|
|
3
|
+
export declare class Analytics {
|
|
4
|
+
private store;
|
|
5
|
+
private maxEvents;
|
|
6
|
+
constructor(store: Store, maxEvents?: number);
|
|
7
|
+
track(ctx: ActorContext, input: JsonRecord): Promise<Row>;
|
|
8
|
+
identify(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
9
|
+
id: string;
|
|
10
|
+
traits: JsonRecord;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
}>;
|
|
13
|
+
private events;
|
|
14
|
+
count(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
15
|
+
total: number;
|
|
16
|
+
groups: {
|
|
17
|
+
key: string;
|
|
18
|
+
count: number;
|
|
19
|
+
}[];
|
|
20
|
+
}>;
|
|
21
|
+
funnel(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
22
|
+
step: string;
|
|
23
|
+
users: number;
|
|
24
|
+
}[]>;
|
|
25
|
+
retention(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
26
|
+
cohort: number;
|
|
27
|
+
days: {
|
|
28
|
+
day: number;
|
|
29
|
+
users: number;
|
|
30
|
+
rate: number | null;
|
|
31
|
+
}[];
|
|
32
|
+
}>;
|
|
33
|
+
cohort(ctx: ActorContext, input: JsonRecord): Promise<string[]>;
|
|
34
|
+
metric(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
35
|
+
count: number;
|
|
36
|
+
sum: number;
|
|
37
|
+
mean: number | null;
|
|
38
|
+
}>;
|
|
39
|
+
experiment(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
40
|
+
variant: string;
|
|
41
|
+
exposed: number;
|
|
42
|
+
converted: number;
|
|
43
|
+
rate: number | null;
|
|
44
|
+
}[]>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { fail, insert, integer, now, strings, text, object } from './primitives.js';
|
|
2
|
+
export class Analytics {
|
|
3
|
+
store;
|
|
4
|
+
maxEvents;
|
|
5
|
+
constructor(store, maxEvents = 50000) {
|
|
6
|
+
this.store = store;
|
|
7
|
+
this.maxEvents = maxEvents;
|
|
8
|
+
}
|
|
9
|
+
async track(ctx, input) {
|
|
10
|
+
return insert(this.store, ctx, 'product-events', {
|
|
11
|
+
name: text(input.name, 'event name', 100),
|
|
12
|
+
subjectId: text(input.subjectId ?? ctx.actorId, 'subjectId', 200),
|
|
13
|
+
groupId: input.groupId === undefined ? null : text(input.groupId),
|
|
14
|
+
properties: object(input.properties ?? {}),
|
|
15
|
+
occurredAt: now(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async identify(ctx, input) {
|
|
19
|
+
const id = text(input.subjectId ?? ctx.actorId, 'subjectId');
|
|
20
|
+
const r = { id, traits: object(input.traits ?? {}), updatedAt: now() };
|
|
21
|
+
await this.store.put(ctx.tenantId, 'analytics-identities', r);
|
|
22
|
+
return r;
|
|
23
|
+
}
|
|
24
|
+
async events(ctx, input) {
|
|
25
|
+
const data = await this.store.list(ctx.tenantId, 'product-events');
|
|
26
|
+
if (data.length > this.maxEvents)
|
|
27
|
+
return fail('Analytics query exceeds local engine; configure analytics provider', 'QUERY_LIMIT', 413);
|
|
28
|
+
const from = input.from === undefined ? 0 : Date.parse(text(input.from)), to = input.to === undefined ? Date.now() : Date.parse(text(input.to));
|
|
29
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || from > to)
|
|
30
|
+
return fail('Invalid time window');
|
|
31
|
+
return data
|
|
32
|
+
.filter((r) => Date.parse(String(r.occurredAt)) >= from && Date.parse(String(r.occurredAt)) <= to)
|
|
33
|
+
.sort((a, b) => String(a.occurredAt).localeCompare(String(b.occurredAt)));
|
|
34
|
+
}
|
|
35
|
+
async count(ctx, input) {
|
|
36
|
+
const events = await this.events(ctx, input);
|
|
37
|
+
const by = String(input.by ?? 'name');
|
|
38
|
+
if (!['name', 'groupId', 'subjectId'].includes(by))
|
|
39
|
+
return fail('Unsupported dimension');
|
|
40
|
+
const counts = new Map();
|
|
41
|
+
for (const r of events) {
|
|
42
|
+
if (input.name && input.name !== r.name)
|
|
43
|
+
continue;
|
|
44
|
+
const key = String(r[by] ?? 'unknown');
|
|
45
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
total: [...counts.values()].reduce((a, b) => a + b, 0),
|
|
49
|
+
groups: [...counts].map(([key, count]) => ({ key, count })),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async funnel(ctx, input) {
|
|
53
|
+
const steps = strings(input.steps);
|
|
54
|
+
if (!steps.length || steps.length > 20)
|
|
55
|
+
return fail('Expected 1–20 steps');
|
|
56
|
+
const progress = new Map();
|
|
57
|
+
for (const r of await this.events(ctx, input)) {
|
|
58
|
+
const id = String(r.subjectId), i = progress.get(id) ?? 0;
|
|
59
|
+
if (r.name === steps[i])
|
|
60
|
+
progress.set(id, i + 1);
|
|
61
|
+
}
|
|
62
|
+
return steps.map((step, i) => ({
|
|
63
|
+
step,
|
|
64
|
+
users: [...progress.values()].filter((n) => n > i).length,
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async retention(ctx, input) {
|
|
68
|
+
const first = text(input.firstEvent), returnEvent = text(input.returnEvent), days = integer(input.days ?? 30, 'days', 1, 365), events = await this.events(ctx, input);
|
|
69
|
+
const starts = new Map(), buckets = Array.from({ length: days + 1 }, () => new Set());
|
|
70
|
+
for (const r of events) {
|
|
71
|
+
const id = String(r.subjectId), at = Date.parse(String(r.occurredAt));
|
|
72
|
+
if (r.name === first && !starts.has(id))
|
|
73
|
+
starts.set(id, at);
|
|
74
|
+
const start = starts.get(id);
|
|
75
|
+
if (start !== undefined && r.name === returnEvent) {
|
|
76
|
+
const day = Math.floor((at - start) / 86400000);
|
|
77
|
+
if (day >= 0 && day <= days)
|
|
78
|
+
buckets[day].add(id);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
cohort: starts.size,
|
|
83
|
+
days: buckets.map((b, day) => ({
|
|
84
|
+
day,
|
|
85
|
+
users: b.size,
|
|
86
|
+
rate: starts.size ? b.size / starts.size : null,
|
|
87
|
+
})),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async cohort(ctx, input) {
|
|
91
|
+
const name = text(input.name);
|
|
92
|
+
return [
|
|
93
|
+
...new Set((await this.events(ctx, input))
|
|
94
|
+
.filter((e) => e.name === name)
|
|
95
|
+
.map((e) => String(e.subjectId))),
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
async metric(ctx, input) {
|
|
99
|
+
const key = text(input.property), name = text(input.name);
|
|
100
|
+
const values = (await this.events(ctx, input))
|
|
101
|
+
.filter((e) => e.name === name)
|
|
102
|
+
.map((e) => object(e.properties ?? {})[key])
|
|
103
|
+
.filter((n) => typeof n === 'number' && Number.isFinite(n));
|
|
104
|
+
return {
|
|
105
|
+
count: values.length,
|
|
106
|
+
sum: values.reduce((a, b) => a + b, 0),
|
|
107
|
+
mean: values.length ? values.reduce((a, b) => a + b, 0) / values.length : null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async experiment(ctx, input) {
|
|
111
|
+
const key = text(input.experimentId), events = (await this.events(ctx, input)).filter((e) => object(e.properties ?? {}).experimentId === key);
|
|
112
|
+
const variants = new Map();
|
|
113
|
+
for (const r of events) {
|
|
114
|
+
const variant = String(object(r.properties ?? {}).variant ?? 'unknown'), v = variants.get(variant) ?? { exposures: new Set(), conversions: new Set() };
|
|
115
|
+
variants.set(variant, v);
|
|
116
|
+
if (r.name === 'experiment.exposure')
|
|
117
|
+
v.exposures.add(String(r.subjectId));
|
|
118
|
+
if (r.name === input.conversionEvent && v.exposures.has(String(r.subjectId)))
|
|
119
|
+
v.conversions.add(String(r.subjectId));
|
|
120
|
+
}
|
|
121
|
+
return [...variants].map(([variant, v]) => ({
|
|
122
|
+
variant,
|
|
123
|
+
exposed: v.exposures.size,
|
|
124
|
+
converted: v.conversions.size,
|
|
125
|
+
rate: v.exposures.size ? v.conversions.size / v.exposures.size : null,
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,MAAM,OAAO,SAAS;IAEV;IACA;IAFV,YACU,KAAY,EACZ,YAAY,KAAK;QADjB,UAAK,GAAL,KAAK,CAAO;QACZ,cAAS,GAAT,SAAS,CAAQ;IACxB,CAAC;IACJ,KAAK,CAAC,KAAK,CAAC,GAAiB,EAAE,KAAiB;QAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,CAAC;YACzC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC;YACjE,OAAO,EAAE,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YACjE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC;YAC1C,UAAU,EAAE,GAAG,EAAE;SAClB,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,QAAQ,CAAC,GAAiB,EAAE,KAAiB;QACjD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,GAAG,CAAC,OAAO,EA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IAAI,CAAC,CAAC,IAAI,KAAK,qBAAqB;gBAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC3E,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,eAAe,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;gBAC1E,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC1C,OAAO;YACP,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI;YACzB,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI;YAC7B,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;SACtE,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActorContext, Store, JsonRecord } from './types.js';
|
|
2
|
+
export interface AuditEvent {
|
|
3
|
+
id: string;
|
|
4
|
+
at: string;
|
|
5
|
+
tenantId: string;
|
|
6
|
+
actorId: string;
|
|
7
|
+
action: string;
|
|
8
|
+
resourceType: string;
|
|
9
|
+
resourceId?: string;
|
|
10
|
+
correlationId?: string;
|
|
11
|
+
impersonatorId?: string;
|
|
12
|
+
detail?: JsonRecord;
|
|
13
|
+
}
|
|
14
|
+
/** Append-only SDK interface; production storage must enforce append-only DB policy and retention. */
|
|
15
|
+
export declare class AuditService {
|
|
16
|
+
private store;
|
|
17
|
+
private enabled;
|
|
18
|
+
constructor(store: Store, enabled: boolean);
|
|
19
|
+
record(ctx: ActorContext, action: string, resourceType: string, resourceId?: string, detail?: JsonRecord, store?: Store): Promise<AuditEvent | undefined>;
|
|
20
|
+
list(ctx: ActorContext, limit?: number): Promise<AuditEvent[]>;
|
|
21
|
+
}
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { redact } from './primitives.js';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
/** Append-only SDK interface; production storage must enforce append-only DB policy and retention. */
|
|
4
|
+
export class AuditService {
|
|
5
|
+
store;
|
|
6
|
+
enabled;
|
|
7
|
+
constructor(store, enabled) {
|
|
8
|
+
this.store = store;
|
|
9
|
+
this.enabled = enabled;
|
|
10
|
+
}
|
|
11
|
+
async record(ctx, action, resourceType, resourceId, detail, store = this.store) {
|
|
12
|
+
if (!this.enabled)
|
|
13
|
+
return;
|
|
14
|
+
const event = {
|
|
15
|
+
id: randomUUID(),
|
|
16
|
+
at: new Date().toISOString(),
|
|
17
|
+
tenantId: ctx.tenantId,
|
|
18
|
+
actorId: ctx.actorId,
|
|
19
|
+
action,
|
|
20
|
+
resourceType,
|
|
21
|
+
resourceId,
|
|
22
|
+
correlationId: ctx.correlationId,
|
|
23
|
+
impersonatorId: ctx.impersonatorId,
|
|
24
|
+
detail: detail ? redact(detail) : undefined,
|
|
25
|
+
};
|
|
26
|
+
await store.put(ctx.tenantId, 'audit', event);
|
|
27
|
+
return event;
|
|
28
|
+
}
|
|
29
|
+
async list(ctx, limit = 100) {
|
|
30
|
+
const events = await this.store.list(ctx.tenantId, 'audit');
|
|
31
|
+
return events
|
|
32
|
+
.sort((a, b) => b.at.localeCompare(a.at))
|
|
33
|
+
.slice(0, Math.max(1, Math.min(limit, 500)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACxC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ActorContext, JsonRecord, Store } from './types.js';
|
|
2
|
+
import type { Row } from './primitives.js';
|
|
3
|
+
export declare class Automation {
|
|
4
|
+
private store;
|
|
5
|
+
private handlers;
|
|
6
|
+
constructor(store: Store);
|
|
7
|
+
registered(name: string): boolean;
|
|
8
|
+
register(name: string, handler: (ctx: ActorContext, payload: JsonRecord, signal: AbortSignal) => Promise<unknown>): void;
|
|
9
|
+
enqueue(ctx: ActorContext, input: JsonRecord): Promise<Row>;
|
|
10
|
+
private outboxStatus;
|
|
11
|
+
claim(ctx: ActorContext, leaseMs?: number): Promise<Row | undefined>;
|
|
12
|
+
finish(ctx: ActorContext, job: Row, ok: boolean): Promise<{
|
|
13
|
+
status: string;
|
|
14
|
+
leaseId: null;
|
|
15
|
+
leaseUntil: null;
|
|
16
|
+
dueAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
id: string;
|
|
19
|
+
createdAt?: string;
|
|
20
|
+
}>;
|
|
21
|
+
work(ctx: ActorContext, deadlineMs?: number): Promise<{
|
|
22
|
+
status: string;
|
|
23
|
+
leaseId: null;
|
|
24
|
+
leaseUntil: null;
|
|
25
|
+
dueAt: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
id: string;
|
|
28
|
+
createdAt?: string;
|
|
29
|
+
} | undefined>;
|
|
30
|
+
requeue(ctx: ActorContext, id: unknown): Promise<{
|
|
31
|
+
status: string;
|
|
32
|
+
attempts: number;
|
|
33
|
+
dueAt: string;
|
|
34
|
+
id: string;
|
|
35
|
+
createdAt?: string;
|
|
36
|
+
updatedAt?: string;
|
|
37
|
+
}>;
|
|
38
|
+
approval(ctx: ActorContext, input: JsonRecord): Promise<Row>;
|
|
39
|
+
decide(ctx: ActorContext, input: JsonRecord): Promise<Row>;
|
|
40
|
+
outbox(ctx: ActorContext, input: JsonRecord): Promise<Row>;
|
|
41
|
+
/** Atomically append event alongside local state. External delivery is at-least-once. */
|
|
42
|
+
publishWithState(ctx: ActorContext, collection: string, data: JsonRecord, event: {
|
|
43
|
+
type: string;
|
|
44
|
+
payload: JsonRecord;
|
|
45
|
+
}): Promise<Row>;
|
|
46
|
+
rule(ctx: ActorContext, input: JsonRecord): Promise<{
|
|
47
|
+
matched: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
}
|