@venturekit-pro/tenancy 0.0.0-dev.20260627215235 → 0.0.0-dev.20260701113915
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/dist/crud/crud.d.ts +46 -0
- package/dist/crud/crud.d.ts.map +1 -0
- package/dist/crud/crud.js +127 -0
- package/dist/crud/crud.js.map +1 -0
- package/dist/crud/index.d.ts +9 -0
- package/dist/crud/index.d.ts.map +1 -0
- package/dist/crud/index.js +8 -0
- package/dist/crud/index.js.map +1 -0
- package/dist/crud/types.d.ts +44 -0
- package/dist/crud/types.d.ts.map +1 -0
- package/dist/crud/types.js +14 -0
- package/dist/crud/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lifecycle/cascade.js +3 -3
- package/dist/lifecycle/cascade.js.map +1 -1
- package/dist/lifecycle/operations.js +2 -2
- package/dist/migrations/0000_vk_tenancy_tenants.sql +4 -4
- package/package.json +4 -4
- package/src/migrations/0000_vk_tenancy_tenants.sql +4 -4
- package/LICENSE +0 -191
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column-agnostic CRUD over `vk_tenants`.
|
|
3
|
+
*
|
|
4
|
+
* Pure SQL against a caller-supplied `Querier`; no `@venturekit/data`
|
|
5
|
+
* import. Reads `SELECT *` so app-added columns ride along (the data
|
|
6
|
+
* client maps them). Writes take a camelCase field bag and infer the
|
|
7
|
+
* right binding per value:
|
|
8
|
+
* - `status` → cast to the `tenant_status` enum.
|
|
9
|
+
* - plain object / array → serialized + cast to `jsonb`.
|
|
10
|
+
* - `Date` / scalar / null → bound as a plain parameter.
|
|
11
|
+
*
|
|
12
|
+
* This lets a consumer that ALTERed extra columns onto `vk_tenants`
|
|
13
|
+
* (e.g. `branding jsonb`, `secret_arn_prefix text`) create / update
|
|
14
|
+
* them through the same helpers without the package knowing the shape.
|
|
15
|
+
*/
|
|
16
|
+
import type { Querier, TenantRecord, TenantStatus, TenantWriteFields } from './types.js';
|
|
17
|
+
/** List every tenant, newest first. */
|
|
18
|
+
export declare function listTenants(querier: Querier): Promise<TenantRecord[]>;
|
|
19
|
+
/** Fetch one tenant by id, or `null` when absent. */
|
|
20
|
+
export declare function getTenantById(querier: Querier, id: string): Promise<TenantRecord | null>;
|
|
21
|
+
/** Fetch one tenant by its unique `slug`, or `null`. */
|
|
22
|
+
export declare function getTenantBySlug(querier: Querier, slug: string): Promise<TenantRecord | null>;
|
|
23
|
+
/** Fetch one tenant by its `primary_domain`, or `null`. */
|
|
24
|
+
export declare function getTenantByPrimaryDomain(querier: Querier, domain: string): Promise<TenantRecord | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Insert a tenant from a camelCase field bag. Omit `id` to let the DB
|
|
27
|
+
* default (`gen_random_uuid()`) assign it. The `slug` unique constraint
|
|
28
|
+
* is DB-enforced — callers map `23505` via `isUniqueViolation`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createTenant(querier: Querier, fields: TenantWriteFields): Promise<TenantRecord>;
|
|
31
|
+
/**
|
|
32
|
+
* Update a tenant from a camelCase field bag. Always bumps `updated_at`.
|
|
33
|
+
* Returns the updated row, or `null` when no tenant matches `id`. A
|
|
34
|
+
* no-op (`fields` empty) still touches `updated_at` and returns the row.
|
|
35
|
+
*/
|
|
36
|
+
export declare function updateTenant(querier: Querier, id: string, fields: TenantWriteFields): Promise<TenantRecord | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Convenience: flip a tenant's lifecycle `status`. Returns the updated
|
|
39
|
+
* row, or `null` when no tenant matches. For richer transitions
|
|
40
|
+
* (stamping `suspended_at` / `archived_at`, cascades) use the lifecycle
|
|
41
|
+
* helpers in `../lifecycle`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function setTenantStatus(querier: Querier, id: string, status: TenantStatus): Promise<TenantRecord | null>;
|
|
44
|
+
/** True when `err` is a Postgres `unique_violation` (23505). */
|
|
45
|
+
export declare function isUniqueViolation(err: unknown): boolean;
|
|
46
|
+
//# sourceMappingURL=crud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../src/crud/crud.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAsCpB,uCAAuC;AACvC,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAI3E;AAED,qDAAqD;AACrD,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAM9B;AAED,wDAAwD;AACxD,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAM9B;AAED,2DAA2D;AAC3D,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAM9B;AAID;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,YAAY,CAAC,CAsBvB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAiB9B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAE9B;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMvD"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column-agnostic CRUD over `vk_tenants`.
|
|
3
|
+
*
|
|
4
|
+
* Pure SQL against a caller-supplied `Querier`; no `@venturekit/data`
|
|
5
|
+
* import. Reads `SELECT *` so app-added columns ride along (the data
|
|
6
|
+
* client maps them). Writes take a camelCase field bag and infer the
|
|
7
|
+
* right binding per value:
|
|
8
|
+
* - `status` → cast to the `tenant_status` enum.
|
|
9
|
+
* - plain object / array → serialized + cast to `jsonb`.
|
|
10
|
+
* - `Date` / scalar / null → bound as a plain parameter.
|
|
11
|
+
*
|
|
12
|
+
* This lets a consumer that ALTERed extra columns onto `vk_tenants`
|
|
13
|
+
* (e.g. `branding jsonb`, `secret_arn_prefix text`) create / update
|
|
14
|
+
* them through the same helpers without the package knowing the shape.
|
|
15
|
+
*/
|
|
16
|
+
/** `displayName` → `display_name`, `additionalDomains` → `additional_domains`. */
|
|
17
|
+
function camelToSnake(key) {
|
|
18
|
+
return key.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a single `column = $n[::cast]` (or VALUES placeholder) for one
|
|
22
|
+
* field, pushing the bound value onto `params`. Centralizes the
|
|
23
|
+
* type-inference rules shared by INSERT + UPDATE.
|
|
24
|
+
*/
|
|
25
|
+
function bindField(key, value, params) {
|
|
26
|
+
const column = camelToSnake(key);
|
|
27
|
+
params.push(value);
|
|
28
|
+
const n = params.length;
|
|
29
|
+
if (key === 'status') {
|
|
30
|
+
return { column, placeholder: `$${n}::tenant_status` };
|
|
31
|
+
}
|
|
32
|
+
const isJsonb = value !== null &&
|
|
33
|
+
typeof value === 'object' &&
|
|
34
|
+
!(value instanceof Date);
|
|
35
|
+
if (isJsonb) {
|
|
36
|
+
// Replace the raw value with its JSON serialization.
|
|
37
|
+
params[n - 1] = JSON.stringify(value);
|
|
38
|
+
return { column, placeholder: `$${n}::jsonb` };
|
|
39
|
+
}
|
|
40
|
+
return { column, placeholder: `$${n}` };
|
|
41
|
+
}
|
|
42
|
+
// ─── Reads ──────────────────────────────────────────────────────────
|
|
43
|
+
/** List every tenant, newest first. */
|
|
44
|
+
export async function listTenants(querier) {
|
|
45
|
+
return querier(`SELECT * FROM vk_tenants ORDER BY created_at DESC`);
|
|
46
|
+
}
|
|
47
|
+
/** Fetch one tenant by id, or `null` when absent. */
|
|
48
|
+
export async function getTenantById(querier, id) {
|
|
49
|
+
const rows = await querier(`SELECT * FROM vk_tenants WHERE id = $1 LIMIT 1`, [id]);
|
|
50
|
+
return rows[0] ?? null;
|
|
51
|
+
}
|
|
52
|
+
/** Fetch one tenant by its unique `slug`, or `null`. */
|
|
53
|
+
export async function getTenantBySlug(querier, slug) {
|
|
54
|
+
const rows = await querier(`SELECT * FROM vk_tenants WHERE slug = $1 LIMIT 1`, [slug]);
|
|
55
|
+
return rows[0] ?? null;
|
|
56
|
+
}
|
|
57
|
+
/** Fetch one tenant by its `primary_domain`, or `null`. */
|
|
58
|
+
export async function getTenantByPrimaryDomain(querier, domain) {
|
|
59
|
+
const rows = await querier(`SELECT * FROM vk_tenants WHERE primary_domain = $1 LIMIT 1`, [domain]);
|
|
60
|
+
return rows[0] ?? null;
|
|
61
|
+
}
|
|
62
|
+
// ─── Writes ─────────────────────────────────────────────────────────
|
|
63
|
+
/**
|
|
64
|
+
* Insert a tenant from a camelCase field bag. Omit `id` to let the DB
|
|
65
|
+
* default (`gen_random_uuid()`) assign it. The `slug` unique constraint
|
|
66
|
+
* is DB-enforced — callers map `23505` via `isUniqueViolation`.
|
|
67
|
+
*/
|
|
68
|
+
export async function createTenant(querier, fields) {
|
|
69
|
+
const keys = Object.keys(fields);
|
|
70
|
+
if (keys.length === 0) {
|
|
71
|
+
throw new Error('createTenant requires at least one field');
|
|
72
|
+
}
|
|
73
|
+
const params = [];
|
|
74
|
+
const columns = [];
|
|
75
|
+
const placeholders = [];
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
const { column, placeholder } = bindField(key, fields[key], params);
|
|
78
|
+
columns.push(column);
|
|
79
|
+
placeholders.push(placeholder);
|
|
80
|
+
}
|
|
81
|
+
const rows = await querier(`INSERT INTO vk_tenants (${columns.join(', ')})
|
|
82
|
+
VALUES (${placeholders.join(', ')})
|
|
83
|
+
RETURNING *`, params);
|
|
84
|
+
const row = rows[0];
|
|
85
|
+
if (!row)
|
|
86
|
+
throw new Error('vk_tenants insert returned no rows');
|
|
87
|
+
return row;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Update a tenant from a camelCase field bag. Always bumps `updated_at`.
|
|
91
|
+
* Returns the updated row, or `null` when no tenant matches `id`. A
|
|
92
|
+
* no-op (`fields` empty) still touches `updated_at` and returns the row.
|
|
93
|
+
*/
|
|
94
|
+
export async function updateTenant(querier, id, fields) {
|
|
95
|
+
const params = [];
|
|
96
|
+
const sets = [];
|
|
97
|
+
for (const key of Object.keys(fields)) {
|
|
98
|
+
const { column, placeholder } = bindField(key, fields[key], params);
|
|
99
|
+
sets.push(`${column} = ${placeholder}`);
|
|
100
|
+
}
|
|
101
|
+
sets.push('updated_at = NOW()');
|
|
102
|
+
params.push(id);
|
|
103
|
+
const rows = await querier(`UPDATE vk_tenants
|
|
104
|
+
SET ${sets.join(', ')}
|
|
105
|
+
WHERE id = $${params.length}
|
|
106
|
+
RETURNING *`, params);
|
|
107
|
+
return rows[0] ?? null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Convenience: flip a tenant's lifecycle `status`. Returns the updated
|
|
111
|
+
* row, or `null` when no tenant matches. For richer transitions
|
|
112
|
+
* (stamping `suspended_at` / `archived_at`, cascades) use the lifecycle
|
|
113
|
+
* helpers in `../lifecycle`.
|
|
114
|
+
*/
|
|
115
|
+
export async function setTenantStatus(querier, id, status) {
|
|
116
|
+
return updateTenant(querier, id, { status });
|
|
117
|
+
}
|
|
118
|
+
/** True when `err` is a Postgres `unique_violation` (23505). */
|
|
119
|
+
export function isUniqueViolation(err) {
|
|
120
|
+
if (err && typeof err === 'object' && 'code' in err) {
|
|
121
|
+
if (err.code === '23505')
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
125
|
+
return /duplicate key|unique constraint/i.test(message);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=crud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.js","sourceRoot":"","sources":["../../src/crud/crud.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,kFAAkF;AAClF,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAChB,GAAW,EACX,KAAc,EACd,MAAiB;IAEjB,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;QACrB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC;IACzD,CAAC;IACD,MAAM,OAAO,GACX,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC;IAC3B,IAAI,OAAO,EAAE,CAAC;QACZ,qDAAqD;QACrD,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KA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B,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChB,MAAM,IAAI,GAAG,MAAM,OAAO,CACxB;cACU,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;oBACT,MAAM,CAAC,MAAM;kBACf,EACd,MAAM,CACP,CAAC;IACF,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAgB,EAChB,EAAU,EACV,MAAoB;IAEpB,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QACpD,IAAK,GAA0B,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;IAChE,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,kCAAkC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vk_tenants` CRUD — column-agnostic create / read / update + types.
|
|
3
|
+
*
|
|
4
|
+
* The lean parent-row primitives. Lifecycle transitions with cascade
|
|
5
|
+
* (suspend / archive / restore / hard-delete) live in `../lifecycle`.
|
|
6
|
+
*/
|
|
7
|
+
export type { TenantStatus, TenantRecord, TenantWriteFields, Querier, } from './types.js';
|
|
8
|
+
export { listTenants, getTenantById, getTenantBySlug, getTenantByPrimaryDomain, createTenant, updateTenant, setTenantStatus, isUniqueViolation, } from './crud.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crud/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,WAAW,EACX,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vk_tenants` CRUD — column-agnostic create / read / update + types.
|
|
3
|
+
*
|
|
4
|
+
* The lean parent-row primitives. Lifecycle transitions with cascade
|
|
5
|
+
* (suspend / archive / restore / hard-delete) live in `../lifecycle`.
|
|
6
|
+
*/
|
|
7
|
+
export { listTenants, getTenantById, getTenantBySlug, getTenantByPrimaryDomain, createTenant, updateTenant, setTenantStatus, isUniqueViolation, } from './crud.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crud/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EACL,WAAW,EACX,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the bare `vk_tenants` CRUD module.
|
|
3
|
+
*
|
|
4
|
+
* The tenancy package owns the lean parent row (`id`, `slug`,
|
|
5
|
+
* `display_name`, `status`, `primary_domain`, lifecycle + `metadata`).
|
|
6
|
+
* Consuming apps may ALTER the table to add their own columns (e.g. the
|
|
7
|
+
* CMS adds `branding` / `settings` / `additional_domains`). The CRUD here
|
|
8
|
+
* is deliberately **column-agnostic**: reads `SELECT *` (the data client
|
|
9
|
+
* auto-maps every column, app-added ones included) and writes accept a
|
|
10
|
+
* camelCase field bag so app columns flow through without the package
|
|
11
|
+
* enumerating them.
|
|
12
|
+
*/
|
|
13
|
+
/** Lifecycle status — mirrors the DB enum `tenant_status`. */
|
|
14
|
+
export type TenantStatus = 'pending' | 'active' | 'suspended' | 'archived' | 'deleted';
|
|
15
|
+
/**
|
|
16
|
+
* A `vk_tenants` row, post-mapping (snake_case → camelCase). The package
|
|
17
|
+
* guarantees the base columns; app-added columns appear too at runtime
|
|
18
|
+
* (the data client maps them) — consumers cast to a wider row type.
|
|
19
|
+
*/
|
|
20
|
+
export interface TenantRecord {
|
|
21
|
+
id: string;
|
|
22
|
+
slug: string;
|
|
23
|
+
displayName: string;
|
|
24
|
+
status: TenantStatus;
|
|
25
|
+
primaryDomain: string | null;
|
|
26
|
+
metadata: Record<string, unknown>;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
updatedAt: Date;
|
|
29
|
+
/** App-added columns (branding, settings, …) surface here at runtime. */
|
|
30
|
+
[column: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A camelCase field bag for create / update. Base columns plus any
|
|
34
|
+
* app-added columns the consumer ALTERed onto `vk_tenants`. Object /
|
|
35
|
+
* array values are written as `jsonb`; `status` is cast to the
|
|
36
|
+
* `tenant_status` enum; everything else binds as a plain param.
|
|
37
|
+
*/
|
|
38
|
+
export type TenantWriteFields = Record<string, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Querier — same shape as the rest of the workspace. Declared locally so
|
|
41
|
+
* the package carries no hard dependency on `@venturekit/data`.
|
|
42
|
+
*/
|
|
43
|
+
export type Querier = <T = Record<string, unknown>[]>(sql: string, params?: unknown[]) => Promise<T>;
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/crud/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,QAAQ,GACR,WAAW,GACX,UAAU,GACV,SAAS,CAAC;AAEd;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;IACrB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,yEAAyE;IACzE,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClD,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the bare `vk_tenants` CRUD module.
|
|
3
|
+
*
|
|
4
|
+
* The tenancy package owns the lean parent row (`id`, `slug`,
|
|
5
|
+
* `display_name`, `status`, `primary_domain`, lifecycle + `metadata`).
|
|
6
|
+
* Consuming apps may ALTER the table to add their own columns (e.g. the
|
|
7
|
+
* CMS adds `branding` / `settings` / `additional_domains`). The CRUD here
|
|
8
|
+
* is deliberately **column-agnostic**: reads `SELECT *` (the data client
|
|
9
|
+
* auto-maps every column, app-added ones included) and writes accept a
|
|
10
|
+
* camelCase field bag so app columns flow through without the package
|
|
11
|
+
* enumerating them.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/crud/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
export * from './types/index.js';
|
|
11
11
|
export { TenantContext, createTenantContext, getCurrentTenant, resolveTenant, } from './context/index.js';
|
|
12
12
|
export * from './middleware/index.js';
|
|
13
|
+
export { listTenants, getTenantById, getTenantBySlug, getTenantByPrimaryDomain, createTenant, updateTenant, setTenantStatus, isUniqueViolation as isTenantUniqueViolation, } from './crud/index.js';
|
|
14
|
+
export type { TenantRecord, TenantWriteFields, TenantStatus as TenantDbStatus, } from './crud/index.js';
|
|
13
15
|
export { suspendTenant, archiveTenant, restoreTenant, hardDeleteTenant, planCascade, executeCascade, } from './lifecycle/index.js';
|
|
14
16
|
export type { TenantLifecycleStatus, LifecycleArgs, LifecycleOperationArgs, HardDeleteArgs, LifecycleAuditEvent, LifecycleAuditSink, CascadePlanEntry, CascadeOptions, CascadeResult, } from './lifecycle/index.js';
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAG5B,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAG5B,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EACL,WAAW,EACX,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,IAAI,uBAAuB,GAC7C,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,iBAAiB,EAGjB,YAAY,IAAI,cAAc,GAC/B,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export * from './types/index.js';
|
|
|
13
13
|
export { createTenantContext, getCurrentTenant, resolveTenant, } from './context/index.js';
|
|
14
14
|
// Middleware
|
|
15
15
|
export * from './middleware/index.js';
|
|
16
|
+
// Bare vk_tenants CRUD (column-agnostic create / read / update)
|
|
17
|
+
export { listTenants, getTenantById, getTenantBySlug, getTenantByPrimaryDomain, createTenant, updateTenant, setTenantStatus, isUniqueViolation as isTenantUniqueViolation, } from './crud/index.js';
|
|
16
18
|
// Lifecycle (suspend / archive / restore / hard-delete + cascade walker)
|
|
17
19
|
export { suspendTenant, archiveTenant, restoreTenant, hardDeleteTenant, planCascade, executeCascade, } from './lifecycle/index.js';
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,UAAU;AACV,OAAO,EAEL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAE5B,aAAa;AACb,cAAc,uBAAuB,CAAC;AAEtC,yEAAyE;AACzE,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,UAAU;AACV,OAAO,EAEL,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAE5B,aAAa;AACb,cAAc,uBAAuB,CAAC;AAEtC,gEAAgE;AAChE,OAAO,EACL,WAAW,EACX,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,IAAI,uBAAuB,GAC7C,MAAM,iBAAiB,CAAC;AASzB,yEAAyE;AACzE,OAAO,EACL,aAAa,EACb,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,GACf,MAAM,sBAAsB,CAAC"}
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
export async function planCascade(querier, options = {}) {
|
|
43
43
|
const schema = options.schema ?? 'public';
|
|
44
44
|
const skip = new Set([
|
|
45
|
-
// `
|
|
45
|
+
// `vk_tenants` is the root we're collapsing into; the helper deletes
|
|
46
46
|
// it separately at the very end. Including it in the cascade
|
|
47
47
|
// would cause a "depends on itself" cycle.
|
|
48
|
-
'
|
|
48
|
+
'vk_tenants',
|
|
49
49
|
...(options.skipTables ?? []),
|
|
50
50
|
]);
|
|
51
51
|
const tables = await querier(`SELECT table_schema AS "schema_name", table_name
|
|
@@ -162,7 +162,7 @@ export async function executeCascade(querier, options) {
|
|
|
162
162
|
counts[entry.tableName] = rows.length;
|
|
163
163
|
}
|
|
164
164
|
// Finally, delete the tenants row itself.
|
|
165
|
-
const tenantsTable = `${schema}.
|
|
165
|
+
const tenantsTable = `${schema}.vk_tenants`;
|
|
166
166
|
const rows = await querier(`DELETE FROM ${tenantsTable} WHERE id = $1 RETURNING 1 AS id`, [options.tenantId]);
|
|
167
167
|
counts[tenantsTable] = rows.length;
|
|
168
168
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cascade.js","sourceRoot":"","sources":["../../src/lifecycle/cascade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAqDH;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAgB,EAChB,UAAyD,EAAE;IAE3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC;QACnB,
|
|
1
|
+
{"version":3,"file":"cascade.js","sourceRoot":"","sources":["../../src/lifecycle/cascade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAqDH;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAgB,EAChB,UAAyD,EAAE;IAE3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC;IAC1C,MAAM,IAAI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AC;IAED,0CAA0C;IAC1C,MAAM,YAAY,GAAG,GAAG,MAAM,aAAa,CAAC;IAC5C,MAAM,IAAI,GAAG,MAAM,OAAO,CACxB,eAAe,YAAY,kCAAkC,EAC7D,CAAC,OAAO,CAAC,QAAQ,CAAC,CACnB,CAAC;IACF,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAEnC,OAAO;QACL,IAAI;QACJ,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -112,7 +112,7 @@ async function mutateStatus(querier, tenantId, status, reason) {
|
|
|
112
112
|
// app-side derived state (e.g. cached counters) is the app's
|
|
113
113
|
// responsibility to refresh.
|
|
114
114
|
if (reason !== undefined && reason !== null) {
|
|
115
|
-
await querier(`UPDATE
|
|
115
|
+
await querier(`UPDATE vk_tenants
|
|
116
116
|
SET status = $2,
|
|
117
117
|
metadata = jsonb_set(
|
|
118
118
|
COALESCE(metadata, '{}'::jsonb),
|
|
@@ -124,7 +124,7 @@ async function mutateStatus(querier, tenantId, status, reason) {
|
|
|
124
124
|
WHERE id = $1`, [tenantId, status, reason]);
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
|
-
await querier(`UPDATE
|
|
127
|
+
await querier(`UPDATE vk_tenants
|
|
128
128
|
SET status = $2,
|
|
129
129
|
updated_at = now()
|
|
130
130
|
WHERE id = $1`, [tenantId, status]);
|
|
@@ -57,7 +57,7 @@ CREATE TYPE tenant_status AS ENUM (
|
|
|
57
57
|
|
|
58
58
|
-- ─── tenants ───────────────────────────────────────────────────────
|
|
59
59
|
|
|
60
|
-
CREATE TABLE IF NOT EXISTS
|
|
60
|
+
CREATE TABLE IF NOT EXISTS vk_tenants (
|
|
61
61
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
62
62
|
-- URL-safe identifier. Used for sub-domains, log lines, S3
|
|
63
63
|
-- prefixes (`<slug>/...`), and the tenant-routing middleware.
|
|
@@ -92,14 +92,14 @@ CREATE TABLE IF NOT EXISTS tenants (
|
|
|
92
92
|
-- Slug is the editor-friendly id used in log lines and S3 prefixes.
|
|
93
93
|
-- Unique on lower(slug) so `Demo` and `demo` collide.
|
|
94
94
|
CREATE UNIQUE INDEX IF NOT EXISTS tenants_slug_unique
|
|
95
|
-
ON
|
|
95
|
+
ON vk_tenants (lower(slug));
|
|
96
96
|
|
|
97
97
|
-- Primary-domain lookup is the hot path for the tenancy middleware
|
|
98
98
|
-- (one query per request before any business logic runs).
|
|
99
99
|
CREATE UNIQUE INDEX IF NOT EXISTS tenants_primary_domain_unique
|
|
100
|
-
ON
|
|
100
|
+
ON vk_tenants (lower(primary_domain))
|
|
101
101
|
WHERE primary_domain IS NOT NULL;
|
|
102
102
|
|
|
103
103
|
-- Status filter for admin "active tenants" dashboards.
|
|
104
104
|
CREATE INDEX IF NOT EXISTS tenants_status_idx
|
|
105
|
-
ON
|
|
105
|
+
ON vk_tenants (status);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit-pro/tenancy",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.20260701113915",
|
|
4
4
|
"description": "Multi-tenant utilities for VentureKit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@venturekit/core": "0.0.0-dev.
|
|
33
|
+
"@venturekit/core": "0.0.0-dev.20260701113915"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@venturekit/runtime": "0.0.0-dev.
|
|
36
|
+
"@venturekit/runtime": "0.0.0-dev.20260701113915"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
39
|
"@venturekit/runtime": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^25.6.0",
|
|
45
|
-
"@venturekit/runtime": "0.0.0-dev.
|
|
45
|
+
"@venturekit/runtime": "0.0.0-dev.20260701113915",
|
|
46
46
|
"typescript": "^5.3.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
@@ -57,7 +57,7 @@ CREATE TYPE tenant_status AS ENUM (
|
|
|
57
57
|
|
|
58
58
|
-- ─── tenants ───────────────────────────────────────────────────────
|
|
59
59
|
|
|
60
|
-
CREATE TABLE IF NOT EXISTS
|
|
60
|
+
CREATE TABLE IF NOT EXISTS vk_tenants (
|
|
61
61
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
62
62
|
-- URL-safe identifier. Used for sub-domains, log lines, S3
|
|
63
63
|
-- prefixes (`<slug>/...`), and the tenant-routing middleware.
|
|
@@ -92,14 +92,14 @@ CREATE TABLE IF NOT EXISTS tenants (
|
|
|
92
92
|
-- Slug is the editor-friendly id used in log lines and S3 prefixes.
|
|
93
93
|
-- Unique on lower(slug) so `Demo` and `demo` collide.
|
|
94
94
|
CREATE UNIQUE INDEX IF NOT EXISTS tenants_slug_unique
|
|
95
|
-
ON
|
|
95
|
+
ON vk_tenants (lower(slug));
|
|
96
96
|
|
|
97
97
|
-- Primary-domain lookup is the hot path for the tenancy middleware
|
|
98
98
|
-- (one query per request before any business logic runs).
|
|
99
99
|
CREATE UNIQUE INDEX IF NOT EXISTS tenants_primary_domain_unique
|
|
100
|
-
ON
|
|
100
|
+
ON vk_tenants (lower(primary_domain))
|
|
101
101
|
WHERE primary_domain IS NOT NULL;
|
|
102
102
|
|
|
103
103
|
-- Status filter for admin "active tenants" dashboards.
|
|
104
104
|
CREATE INDEX IF NOT EXISTS tenants_status_idx
|
|
105
|
-
ON
|
|
105
|
+
ON vk_tenants (status);
|
package/LICENSE
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Apache License
|
|
3
|
-
Version 2.0, January 2004
|
|
4
|
-
http://www.apache.org/licenses/
|
|
5
|
-
|
|
6
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
-
|
|
8
|
-
1. Definitions.
|
|
9
|
-
|
|
10
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
-
|
|
13
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
-
the copyright owner that is granting the License.
|
|
15
|
-
|
|
16
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
-
other entities that control, are controlled by, or are under common
|
|
18
|
-
control with that entity. For the purposes of this definition,
|
|
19
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
-
direction or management of such entity, whether by contract or
|
|
21
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
-
|
|
24
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
-
exercising permissions granted by this License.
|
|
26
|
-
|
|
27
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
-
including but not limited to software source code, documentation
|
|
29
|
-
source, and configuration files.
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding any notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
Copyright 2025 VentureKit Contributors
|
|
180
|
-
|
|
181
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
-
you may not use this file except in compliance with the License.
|
|
183
|
-
You may obtain a copy of the License at
|
|
184
|
-
|
|
185
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
-
|
|
187
|
-
Unless required by applicable law or agreed to in writing, software
|
|
188
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
-
See the License for the specific language governing permissions and
|
|
191
|
-
limitations under the License.
|