@vritti/api-sdk 0.3.2 → 0.3.5
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/auth.cjs +942 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +95 -0
- package/dist/auth.d.ts +95 -0
- package/dist/auth.js +884 -0
- package/dist/auth.js.map +1 -0
- package/dist/cache.cjs +182 -14
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.cts +48 -4
- package/dist/cache.d.ts +48 -4
- package/dist/cache.js +177 -12
- package/dist/cache.js.map +1 -1
- package/dist/catalog-resolver.cjs +226 -51
- package/dist/catalog-resolver.cjs.map +1 -1
- package/dist/catalog-resolver.d.cts +41 -19
- package/dist/catalog-resolver.d.ts +41 -19
- package/dist/catalog-resolver.js +212 -46
- package/dist/catalog-resolver.js.map +1 -1
- package/dist/code-pattern-BP4zkNtT.d.cts +12 -0
- package/dist/code-pattern-BP4zkNtT.d.ts +12 -0
- package/dist/context.cjs +93 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +19 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +64 -0
- package/dist/context.js.map +1 -0
- package/dist/countries.cjs +1559 -0
- package/dist/countries.cjs.map +1 -0
- package/dist/countries.d.cts +13 -0
- package/dist/countries.d.ts +13 -0
- package/dist/countries.js +1532 -0
- package/dist/countries.js.map +1 -0
- package/dist/data-table.cjs +1280 -0
- package/dist/data-table.cjs.map +1 -0
- package/dist/data-table.d.cts +123 -0
- package/dist/data-table.d.ts +123 -0
- package/dist/data-table.js +1260 -0
- package/dist/data-table.js.map +1 -0
- package/dist/database.cjs +1510 -0
- package/dist/database.cjs.map +1 -0
- package/dist/database.d.cts +287 -0
- package/dist/database.d.ts +287 -0
- package/dist/database.js +1469 -0
- package/dist/database.js.map +1 -0
- package/dist/decimal.d.cts +0 -1
- package/dist/decimal.d.ts +0 -1
- package/dist/decorators.cjs +1817 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +24 -0
- package/dist/decorators.d.ts +24 -0
- package/dist/decorators.js +1780 -0
- package/dist/decorators.js.map +1 -0
- package/dist/document-BoS0NIbf.d.cts +12 -0
- package/dist/document-BoS0NIbf.d.ts +12 -0
- package/dist/drizzle-pg-core.cjs +25 -0
- package/dist/drizzle-pg-core.cjs.map +1 -1
- package/dist/drizzle-pg-core.d.cts +7 -0
- package/dist/drizzle-pg-core.d.ts +7 -0
- package/dist/drizzle-pg-core.js +22 -0
- package/dist/drizzle-pg-core.js.map +1 -1
- package/dist/exceptions.cjs +301 -0
- package/dist/exceptions.cjs.map +1 -0
- package/dist/exceptions.d.cts +90 -0
- package/dist/exceptions.d.ts +90 -0
- package/dist/exceptions.js +257 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/filter.types-PuARU9XD.d.cts +50 -0
- package/dist/filter.types-PuARU9XD.d.ts +50 -0
- package/dist/filters.cjs +407 -0
- package/dist/filters.cjs.map +1 -0
- package/dist/filters.d.cts +55 -0
- package/dist/filters.d.ts +55 -0
- package/dist/filters.js +377 -0
- package/dist/filters.js.map +1 -0
- package/dist/index.cjs +0 -5423
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -854
- package/dist/index.d.ts +93 -854
- package/dist/index.js +0 -5301
- package/dist/index.js.map +1 -1
- package/dist/is-country.decorator-CcNwSSr5.d.cts +5 -0
- package/dist/is-country.decorator-CcNwSSr5.d.ts +5 -0
- package/dist/license.cjs +9 -56
- package/dist/license.cjs.map +1 -1
- package/dist/license.d.cts +3 -14
- package/dist/license.d.ts +3 -14
- package/dist/license.js +8 -51
- package/dist/license.js.map +1 -1
- package/dist/lodash.cjs.map +1 -1
- package/dist/lodash.js.map +1 -1
- package/dist/logger.cjs +862 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +118 -0
- package/dist/logger.d.ts +118 -0
- package/dist/logger.js +816 -0
- package/dist/logger.js.map +1 -0
- package/dist/migrate.cjs +2 -2
- package/dist/migrate.cjs.map +1 -1
- package/dist/migrate.d.cts +2 -0
- package/dist/migrate.d.ts +2 -0
- package/dist/migrate.js +2 -2
- package/dist/migrate.js.map +1 -1
- package/dist/money.cjs +18 -3
- package/dist/money.cjs.map +1 -1
- package/dist/money.d.cts +13 -13
- package/dist/money.d.ts +13 -13
- package/dist/money.js +18 -3
- package/dist/money.js.map +1 -1
- package/dist/nats.cjs +34 -35
- package/dist/nats.cjs.map +1 -1
- package/dist/nats.d.cts +14 -14
- package/dist/nats.d.ts +14 -14
- package/dist/nats.js +32 -33
- package/dist/nats.js.map +1 -1
- package/dist/root.cjs +225 -0
- package/dist/root.cjs.map +1 -0
- package/dist/root.d.cts +4 -0
- package/dist/root.d.ts +4 -0
- package/dist/root.js +200 -0
- package/dist/root.js.map +1 -0
- package/dist/signing.cjs +159 -0
- package/dist/signing.cjs.map +1 -0
- package/dist/signing.d.cts +35 -0
- package/dist/signing.d.ts +35 -0
- package/dist/signing.js +128 -0
- package/dist/signing.js.map +1 -0
- package/dist/{types-DQRwj5rr.d.cts → types-C9jPdQqH.d.cts} +32 -6
- package/dist/{types-DQRwj5rr.d.ts → types-C9jPdQqH.d.ts} +32 -6
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +17 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +273 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +245 -0
- package/dist/utils.js.map +1 -0
- package/package.json +132 -1
- package/dist/cache.service-_SuJIcNA.d.cts +0 -20
- package/dist/cache.service-_SuJIcNA.d.ts +0 -20
- package/dist/fastify-augmentation-CQPBNS5a.d.cts +0 -105
- package/dist/fastify-augmentation-CQPBNS5a.d.ts +0 -105
package/dist/signing.cjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/signing/index.ts
|
|
22
|
+
var signing_exports = {};
|
|
23
|
+
__export(signing_exports, {
|
|
24
|
+
buildRequestCanonical: () => buildRequestCanonical,
|
|
25
|
+
canonicalStringify: () => canonicalStringify,
|
|
26
|
+
generateSigningKeyPair: () => generateSigningKeyPair,
|
|
27
|
+
signDocument: () => signDocument,
|
|
28
|
+
signRequestHeaders: () => signRequestHeaders,
|
|
29
|
+
verifyDocument: () => verifyDocument,
|
|
30
|
+
verifySignedRequest: () => verifySignedRequest
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(signing_exports);
|
|
33
|
+
|
|
34
|
+
// src/signing/canonical.ts
|
|
35
|
+
function canonicalStringify(value) {
|
|
36
|
+
return JSON.stringify(sortKeysDeep(value));
|
|
37
|
+
}
|
|
38
|
+
__name(canonicalStringify, "canonicalStringify");
|
|
39
|
+
function sortKeysDeep(value) {
|
|
40
|
+
if (Array.isArray(value)) return value.map(sortKeysDeep);
|
|
41
|
+
if (value !== null && typeof value === "object") {
|
|
42
|
+
const record = value;
|
|
43
|
+
const sorted = {};
|
|
44
|
+
for (const key of Object.keys(record).sort()) sorted[key] = sortKeysDeep(record[key]);
|
|
45
|
+
return sorted;
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
__name(sortKeysDeep, "sortKeysDeep");
|
|
50
|
+
|
|
51
|
+
// src/signing/document.ts
|
|
52
|
+
var import_node_crypto = require("crypto");
|
|
53
|
+
function generateSigningKeyPair() {
|
|
54
|
+
const { privateKey, publicKey } = (0, import_node_crypto.generateKeyPairSync)("ed25519");
|
|
55
|
+
return {
|
|
56
|
+
privateKey: privateKey.export({
|
|
57
|
+
type: "pkcs8",
|
|
58
|
+
format: "der"
|
|
59
|
+
}).toString("base64"),
|
|
60
|
+
publicKey: publicKey.export({
|
|
61
|
+
type: "spki",
|
|
62
|
+
format: "der"
|
|
63
|
+
}).toString("base64")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
__name(generateSigningKeyPair, "generateSigningKeyPair");
|
|
67
|
+
function signDocument(payload, privateKeyBase64) {
|
|
68
|
+
const key = (0, import_node_crypto.createPrivateKey)({
|
|
69
|
+
key: Buffer.from(privateKeyBase64, "base64"),
|
|
70
|
+
format: "der",
|
|
71
|
+
type: "pkcs8"
|
|
72
|
+
});
|
|
73
|
+
const signature = (0, import_node_crypto.sign)(null, Buffer.from(canonicalStringify(payload), "utf8"), key).toString("base64");
|
|
74
|
+
return {
|
|
75
|
+
payload,
|
|
76
|
+
signature
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
__name(signDocument, "signDocument");
|
|
80
|
+
function verifyDocument(doc, publicKeyBase64) {
|
|
81
|
+
try {
|
|
82
|
+
const key = (0, import_node_crypto.createPublicKey)({
|
|
83
|
+
key: Buffer.from(publicKeyBase64, "base64"),
|
|
84
|
+
format: "der",
|
|
85
|
+
type: "spki"
|
|
86
|
+
});
|
|
87
|
+
return (0, import_node_crypto.verify)(null, Buffer.from(canonicalStringify(doc.payload), "utf8"), key, Buffer.from(doc.signature, "base64"));
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
__name(verifyDocument, "verifyDocument");
|
|
93
|
+
|
|
94
|
+
// src/signing/request.ts
|
|
95
|
+
var import_node_crypto2 = require("crypto");
|
|
96
|
+
function buildRequestCanonical(input) {
|
|
97
|
+
const bodyHash = (0, import_node_crypto2.createHash)("sha256").update(input.body ?? "").digest("hex");
|
|
98
|
+
return [
|
|
99
|
+
input.method.toUpperCase(),
|
|
100
|
+
input.path,
|
|
101
|
+
input.orgId ?? "",
|
|
102
|
+
bodyHash,
|
|
103
|
+
String(input.timestamp)
|
|
104
|
+
].join("\n");
|
|
105
|
+
}
|
|
106
|
+
__name(buildRequestCanonical, "buildRequestCanonical");
|
|
107
|
+
function signRequestHeaders(input, privateKeyBase64) {
|
|
108
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
109
|
+
const canonical = buildRequestCanonical({
|
|
110
|
+
...input,
|
|
111
|
+
timestamp
|
|
112
|
+
});
|
|
113
|
+
const key = (0, import_node_crypto2.createPrivateKey)({
|
|
114
|
+
key: Buffer.from(privateKeyBase64, "base64"),
|
|
115
|
+
format: "der",
|
|
116
|
+
type: "pkcs8"
|
|
117
|
+
});
|
|
118
|
+
const signature = (0, import_node_crypto2.sign)(null, Buffer.from(canonical, "utf8"), key).toString("base64");
|
|
119
|
+
return {
|
|
120
|
+
"x-timestamp": String(timestamp),
|
|
121
|
+
"x-signature": signature
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
__name(signRequestHeaders, "signRequestHeaders");
|
|
125
|
+
function verifySignedRequest(input) {
|
|
126
|
+
try {
|
|
127
|
+
const timestamp = Number(input.timestamp);
|
|
128
|
+
if (!Number.isFinite(timestamp)) return false;
|
|
129
|
+
const maxSkew = input.maxSkewSeconds ?? 300;
|
|
130
|
+
if (Math.abs(Math.floor(Date.now() / 1e3) - timestamp) > maxSkew) return false;
|
|
131
|
+
const canonical = buildRequestCanonical({
|
|
132
|
+
method: input.method,
|
|
133
|
+
path: input.path,
|
|
134
|
+
orgId: input.orgId,
|
|
135
|
+
body: input.rawBody,
|
|
136
|
+
timestamp
|
|
137
|
+
});
|
|
138
|
+
const key = (0, import_node_crypto2.createPublicKey)({
|
|
139
|
+
key: Buffer.from(input.publicKey, "base64"),
|
|
140
|
+
format: "der",
|
|
141
|
+
type: "spki"
|
|
142
|
+
});
|
|
143
|
+
return (0, import_node_crypto2.verify)(null, Buffer.from(canonical, "utf8"), key, Buffer.from(input.signature, "base64"));
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
__name(verifySignedRequest, "verifySignedRequest");
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
buildRequestCanonical,
|
|
152
|
+
canonicalStringify,
|
|
153
|
+
generateSigningKeyPair,
|
|
154
|
+
signDocument,
|
|
155
|
+
signRequestHeaders,
|
|
156
|
+
verifyDocument,
|
|
157
|
+
verifySignedRequest
|
|
158
|
+
});
|
|
159
|
+
//# sourceMappingURL=signing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/signing/index.ts","../src/signing/canonical.ts","../src/signing/document.ts","../src/signing/request.ts"],"sourcesContent":["// Signing module — Ed25519 primitives: keypairs, canonical-JSON document signing, and signed control-plane requests\nexport { canonicalStringify } from './canonical';\nexport { generateSigningKeyPair, type SignedDocument, signDocument, verifyDocument } from './document';\nexport {\n buildRequestCanonical,\n type RequestCanonicalInput,\n type SignRequestInput,\n signRequestHeaders,\n type VerifySignedRequestInput,\n verifySignedRequest,\n} from './request';\n","// Serializes a value as deterministic JSON: object keys recursively sorted, arrays keep their order\nexport function canonicalStringify(value: unknown): string {\n return JSON.stringify(sortKeysDeep(value));\n}\n\n// Recursively rebuilds objects with sorted keys so JSON.stringify output is order-independent\nfunction sortKeysDeep(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(sortKeysDeep);\n if (value !== null && typeof value === 'object') {\n const record = value as Record<string, unknown>;\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(record).sort()) sorted[key] = sortKeysDeep(record[key]);\n return sorted;\n }\n return value;\n}\n","import { createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from 'node:crypto';\nimport { canonicalStringify } from './canonical';\n\nexport interface SignedDocument<T> {\n payload: T;\n signature: string;\n}\n\n// Generates an Ed25519 key pair as base64 DER strings (pkcs8 private / spki public)\nexport function generateSigningKeyPair(): { privateKey: string; publicKey: string } {\n const { privateKey, publicKey } = generateKeyPairSync('ed25519');\n return {\n privateKey: privateKey.export({ type: 'pkcs8', format: 'der' }).toString('base64'),\n publicKey: publicKey.export({ type: 'spki', format: 'der' }).toString('base64'),\n };\n}\n\n// Signs a payload's canonical JSON with an Ed25519 private key (base64 pkcs8 DER)\nexport function signDocument<T>(payload: T, privateKeyBase64: string): SignedDocument<T> {\n const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, 'base64'), format: 'der', type: 'pkcs8' });\n const signature = sign(null, Buffer.from(canonicalStringify(payload), 'utf8'), key).toString('base64');\n return { payload, signature };\n}\n\n// Verifies a signed document against an Ed25519 public key (base64 spki DER); malformed input ⇒ false\nexport function verifyDocument<T>(doc: SignedDocument<T>, publicKeyBase64: string): boolean {\n try {\n const key = createPublicKey({ key: Buffer.from(publicKeyBase64, 'base64'), format: 'der', type: 'spki' });\n return verify(\n null,\n Buffer.from(canonicalStringify(doc.payload), 'utf8'),\n key,\n Buffer.from(doc.signature, 'base64'),\n );\n } catch {\n return false;\n }\n}\n","import { createHash, createPrivateKey, createPublicKey, sign, verify } from 'node:crypto';\n\nexport interface RequestCanonicalInput {\n method: string;\n path: string;\n orgId?: string;\n body?: string | Buffer;\n timestamp: number;\n}\n\nexport interface SignRequestInput {\n method: string;\n path: string;\n orgId?: string;\n body?: string | Buffer;\n}\n\nexport interface VerifySignedRequestInput {\n method: string;\n path: string;\n orgId?: string;\n rawBody?: string | Buffer;\n timestamp: string | number;\n signature: string;\n publicKey: string;\n maxSkewSeconds?: number;\n}\n\n// Builds the canonical string signed for a control-plane request: METHOD\\npath\\norgId\\nsha256hex(body)\\ntimestamp\nexport function buildRequestCanonical(input: RequestCanonicalInput): string {\n const bodyHash = createHash('sha256')\n .update(input.body ?? '')\n .digest('hex');\n return [input.method.toUpperCase(), input.path, input.orgId ?? '', bodyHash, String(input.timestamp)].join('\\n');\n}\n\n// Signs a request with an Ed25519 private key (base64 pkcs8 DER), stamping the current unix time\nexport function signRequestHeaders(\n input: SignRequestInput,\n privateKeyBase64: string,\n): { 'x-timestamp': string; 'x-signature': string } {\n const timestamp = Math.floor(Date.now() / 1000);\n const canonical = buildRequestCanonical({ ...input, timestamp });\n const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, 'base64'), format: 'der', type: 'pkcs8' });\n const signature = sign(null, Buffer.from(canonical, 'utf8'), key).toString('base64');\n return { 'x-timestamp': String(timestamp), 'x-signature': signature };\n}\n\n// Verifies a signed request (signature + timestamp skew) against an Ed25519 public key; malformed input ⇒ false\nexport function verifySignedRequest(input: VerifySignedRequestInput): boolean {\n try {\n const timestamp = Number(input.timestamp);\n if (!Number.isFinite(timestamp)) return false;\n const maxSkew = input.maxSkewSeconds ?? 300;\n if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > maxSkew) return false;\n const canonical = buildRequestCanonical({\n method: input.method,\n path: input.path,\n orgId: input.orgId,\n body: input.rawBody,\n timestamp,\n });\n const key = createPublicKey({ key: Buffer.from(input.publicKey, 'base64'), format: 'der', type: 'spki' });\n return verify(null, Buffer.from(canonical, 'utf8'), key, Buffer.from(input.signature, 'base64'));\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;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QAAQN,MAAMM;MACdE,MAAMR,MAAMQ;MACZC,OAAOT,MAAMS;MACbL,MAAMJ,MAAMmC;MACZxB;IACF,CAAA;AACA,UAAMS,UAAMgB,qCAAgB;MAAEhB,KAAKE,OAAOC,KAAKvB,MAAMqC,WAAW,QAAA;MAAWb,QAAQ;MAAOC,MAAM;IAAO,CAAA;AACvG,eAAOa,4BAAO,MAAMhB,OAAOC,KAAKJ,WAAW,MAAA,GAASC,KAAKE,OAAOC,KAAKvB,MAAM0B,WAAW,QAAA,CAAA;EACxF,QAAQ;AACN,WAAO;EACT;AACF;AAlBgBG;","names":["canonicalStringify","value","JSON","stringify","sortKeysDeep","Array","isArray","map","record","sorted","key","Object","keys","sort","generateSigningKeyPair","privateKey","publicKey","generateKeyPairSync","export","type","format","toString","signDocument","payload","privateKeyBase64","key","createPrivateKey","Buffer","from","signature","sign","canonicalStringify","verifyDocument","doc","publicKeyBase64","createPublicKey","verify","import_node_crypto","buildRequestCanonical","input","bodyHash","createHash","update","body","digest","method","toUpperCase","path","orgId","String","timestamp","join","signRequestHeaders","privateKeyBase64","Math","floor","Date","now","canonical","key","createPrivateKey","Buffer","from","format","type","signature","sign","toString","verifySignedRequest","Number","isFinite","maxSkew","maxSkewSeconds","abs","rawBody","createPublicKey","publicKey","verify"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { S as SignedDocument, g as generateSigningKeyPair, s as signDocument, v as verifyDocument } from './document-BoS0NIbf.cjs';
|
|
2
|
+
|
|
3
|
+
declare function canonicalStringify(value: unknown): string;
|
|
4
|
+
|
|
5
|
+
interface RequestCanonicalInput {
|
|
6
|
+
method: string;
|
|
7
|
+
path: string;
|
|
8
|
+
orgId?: string;
|
|
9
|
+
body?: string | Buffer;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
interface SignRequestInput {
|
|
13
|
+
method: string;
|
|
14
|
+
path: string;
|
|
15
|
+
orgId?: string;
|
|
16
|
+
body?: string | Buffer;
|
|
17
|
+
}
|
|
18
|
+
interface VerifySignedRequestInput {
|
|
19
|
+
method: string;
|
|
20
|
+
path: string;
|
|
21
|
+
orgId?: string;
|
|
22
|
+
rawBody?: string | Buffer;
|
|
23
|
+
timestamp: string | number;
|
|
24
|
+
signature: string;
|
|
25
|
+
publicKey: string;
|
|
26
|
+
maxSkewSeconds?: number;
|
|
27
|
+
}
|
|
28
|
+
declare function buildRequestCanonical(input: RequestCanonicalInput): string;
|
|
29
|
+
declare function signRequestHeaders(input: SignRequestInput, privateKeyBase64: string): {
|
|
30
|
+
'x-timestamp': string;
|
|
31
|
+
'x-signature': string;
|
|
32
|
+
};
|
|
33
|
+
declare function verifySignedRequest(input: VerifySignedRequestInput): boolean;
|
|
34
|
+
|
|
35
|
+
export { type RequestCanonicalInput, type SignRequestInput, type VerifySignedRequestInput, buildRequestCanonical, canonicalStringify, signRequestHeaders, verifySignedRequest };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { S as SignedDocument, g as generateSigningKeyPair, s as signDocument, v as verifyDocument } from './document-BoS0NIbf.js';
|
|
2
|
+
|
|
3
|
+
declare function canonicalStringify(value: unknown): string;
|
|
4
|
+
|
|
5
|
+
interface RequestCanonicalInput {
|
|
6
|
+
method: string;
|
|
7
|
+
path: string;
|
|
8
|
+
orgId?: string;
|
|
9
|
+
body?: string | Buffer;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
interface SignRequestInput {
|
|
13
|
+
method: string;
|
|
14
|
+
path: string;
|
|
15
|
+
orgId?: string;
|
|
16
|
+
body?: string | Buffer;
|
|
17
|
+
}
|
|
18
|
+
interface VerifySignedRequestInput {
|
|
19
|
+
method: string;
|
|
20
|
+
path: string;
|
|
21
|
+
orgId?: string;
|
|
22
|
+
rawBody?: string | Buffer;
|
|
23
|
+
timestamp: string | number;
|
|
24
|
+
signature: string;
|
|
25
|
+
publicKey: string;
|
|
26
|
+
maxSkewSeconds?: number;
|
|
27
|
+
}
|
|
28
|
+
declare function buildRequestCanonical(input: RequestCanonicalInput): string;
|
|
29
|
+
declare function signRequestHeaders(input: SignRequestInput, privateKeyBase64: string): {
|
|
30
|
+
'x-timestamp': string;
|
|
31
|
+
'x-signature': string;
|
|
32
|
+
};
|
|
33
|
+
declare function verifySignedRequest(input: VerifySignedRequestInput): boolean;
|
|
34
|
+
|
|
35
|
+
export { type RequestCanonicalInput, type SignRequestInput, type VerifySignedRequestInput, buildRequestCanonical, canonicalStringify, signRequestHeaders, verifySignedRequest };
|
package/dist/signing.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/signing/canonical.ts
|
|
5
|
+
function canonicalStringify(value) {
|
|
6
|
+
return JSON.stringify(sortKeysDeep(value));
|
|
7
|
+
}
|
|
8
|
+
__name(canonicalStringify, "canonicalStringify");
|
|
9
|
+
function sortKeysDeep(value) {
|
|
10
|
+
if (Array.isArray(value)) return value.map(sortKeysDeep);
|
|
11
|
+
if (value !== null && typeof value === "object") {
|
|
12
|
+
const record = value;
|
|
13
|
+
const sorted = {};
|
|
14
|
+
for (const key of Object.keys(record).sort()) sorted[key] = sortKeysDeep(record[key]);
|
|
15
|
+
return sorted;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
__name(sortKeysDeep, "sortKeysDeep");
|
|
20
|
+
|
|
21
|
+
// src/signing/document.ts
|
|
22
|
+
import { createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from "crypto";
|
|
23
|
+
function generateSigningKeyPair() {
|
|
24
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
|
|
25
|
+
return {
|
|
26
|
+
privateKey: privateKey.export({
|
|
27
|
+
type: "pkcs8",
|
|
28
|
+
format: "der"
|
|
29
|
+
}).toString("base64"),
|
|
30
|
+
publicKey: publicKey.export({
|
|
31
|
+
type: "spki",
|
|
32
|
+
format: "der"
|
|
33
|
+
}).toString("base64")
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
__name(generateSigningKeyPair, "generateSigningKeyPair");
|
|
37
|
+
function signDocument(payload, privateKeyBase64) {
|
|
38
|
+
const key = createPrivateKey({
|
|
39
|
+
key: Buffer.from(privateKeyBase64, "base64"),
|
|
40
|
+
format: "der",
|
|
41
|
+
type: "pkcs8"
|
|
42
|
+
});
|
|
43
|
+
const signature = sign(null, Buffer.from(canonicalStringify(payload), "utf8"), key).toString("base64");
|
|
44
|
+
return {
|
|
45
|
+
payload,
|
|
46
|
+
signature
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
__name(signDocument, "signDocument");
|
|
50
|
+
function verifyDocument(doc, publicKeyBase64) {
|
|
51
|
+
try {
|
|
52
|
+
const key = createPublicKey({
|
|
53
|
+
key: Buffer.from(publicKeyBase64, "base64"),
|
|
54
|
+
format: "der",
|
|
55
|
+
type: "spki"
|
|
56
|
+
});
|
|
57
|
+
return verify(null, Buffer.from(canonicalStringify(doc.payload), "utf8"), key, Buffer.from(doc.signature, "base64"));
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
__name(verifyDocument, "verifyDocument");
|
|
63
|
+
|
|
64
|
+
// src/signing/request.ts
|
|
65
|
+
import { createHash, createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey2, sign as sign2, verify as verify2 } from "crypto";
|
|
66
|
+
function buildRequestCanonical(input) {
|
|
67
|
+
const bodyHash = createHash("sha256").update(input.body ?? "").digest("hex");
|
|
68
|
+
return [
|
|
69
|
+
input.method.toUpperCase(),
|
|
70
|
+
input.path,
|
|
71
|
+
input.orgId ?? "",
|
|
72
|
+
bodyHash,
|
|
73
|
+
String(input.timestamp)
|
|
74
|
+
].join("\n");
|
|
75
|
+
}
|
|
76
|
+
__name(buildRequestCanonical, "buildRequestCanonical");
|
|
77
|
+
function signRequestHeaders(input, privateKeyBase64) {
|
|
78
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
79
|
+
const canonical = buildRequestCanonical({
|
|
80
|
+
...input,
|
|
81
|
+
timestamp
|
|
82
|
+
});
|
|
83
|
+
const key = createPrivateKey2({
|
|
84
|
+
key: Buffer.from(privateKeyBase64, "base64"),
|
|
85
|
+
format: "der",
|
|
86
|
+
type: "pkcs8"
|
|
87
|
+
});
|
|
88
|
+
const signature = sign2(null, Buffer.from(canonical, "utf8"), key).toString("base64");
|
|
89
|
+
return {
|
|
90
|
+
"x-timestamp": String(timestamp),
|
|
91
|
+
"x-signature": signature
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
__name(signRequestHeaders, "signRequestHeaders");
|
|
95
|
+
function verifySignedRequest(input) {
|
|
96
|
+
try {
|
|
97
|
+
const timestamp = Number(input.timestamp);
|
|
98
|
+
if (!Number.isFinite(timestamp)) return false;
|
|
99
|
+
const maxSkew = input.maxSkewSeconds ?? 300;
|
|
100
|
+
if (Math.abs(Math.floor(Date.now() / 1e3) - timestamp) > maxSkew) return false;
|
|
101
|
+
const canonical = buildRequestCanonical({
|
|
102
|
+
method: input.method,
|
|
103
|
+
path: input.path,
|
|
104
|
+
orgId: input.orgId,
|
|
105
|
+
body: input.rawBody,
|
|
106
|
+
timestamp
|
|
107
|
+
});
|
|
108
|
+
const key = createPublicKey2({
|
|
109
|
+
key: Buffer.from(input.publicKey, "base64"),
|
|
110
|
+
format: "der",
|
|
111
|
+
type: "spki"
|
|
112
|
+
});
|
|
113
|
+
return verify2(null, Buffer.from(canonical, "utf8"), key, Buffer.from(input.signature, "base64"));
|
|
114
|
+
} catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
__name(verifySignedRequest, "verifySignedRequest");
|
|
119
|
+
export {
|
|
120
|
+
buildRequestCanonical,
|
|
121
|
+
canonicalStringify,
|
|
122
|
+
generateSigningKeyPair,
|
|
123
|
+
signDocument,
|
|
124
|
+
signRequestHeaders,
|
|
125
|
+
verifyDocument,
|
|
126
|
+
verifySignedRequest
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/signing/canonical.ts","../src/signing/document.ts","../src/signing/request.ts"],"sourcesContent":["// Serializes a value as deterministic JSON: object keys recursively sorted, arrays keep their order\nexport function canonicalStringify(value: unknown): string {\n return JSON.stringify(sortKeysDeep(value));\n}\n\n// Recursively rebuilds objects with sorted keys so JSON.stringify output is order-independent\nfunction sortKeysDeep(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(sortKeysDeep);\n if (value !== null && typeof value === 'object') {\n const record = value as Record<string, unknown>;\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(record).sort()) sorted[key] = sortKeysDeep(record[key]);\n return sorted;\n }\n return value;\n}\n","import { createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from 'node:crypto';\nimport { canonicalStringify } from './canonical';\n\nexport interface SignedDocument<T> {\n payload: T;\n signature: string;\n}\n\n// Generates an Ed25519 key pair as base64 DER strings (pkcs8 private / spki public)\nexport function generateSigningKeyPair(): { privateKey: string; publicKey: string } {\n const { privateKey, publicKey } = generateKeyPairSync('ed25519');\n return {\n privateKey: privateKey.export({ type: 'pkcs8', format: 'der' }).toString('base64'),\n publicKey: publicKey.export({ type: 'spki', format: 'der' }).toString('base64'),\n };\n}\n\n// Signs a payload's canonical JSON with an Ed25519 private key (base64 pkcs8 DER)\nexport function signDocument<T>(payload: T, privateKeyBase64: string): SignedDocument<T> {\n const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, 'base64'), format: 'der', type: 'pkcs8' });\n const signature = sign(null, Buffer.from(canonicalStringify(payload), 'utf8'), key).toString('base64');\n return { payload, signature };\n}\n\n// Verifies a signed document against an Ed25519 public key (base64 spki DER); malformed input ⇒ false\nexport function verifyDocument<T>(doc: SignedDocument<T>, publicKeyBase64: string): boolean {\n try {\n const key = createPublicKey({ key: Buffer.from(publicKeyBase64, 'base64'), format: 'der', type: 'spki' });\n return verify(\n null,\n Buffer.from(canonicalStringify(doc.payload), 'utf8'),\n key,\n Buffer.from(doc.signature, 'base64'),\n );\n } catch {\n return false;\n }\n}\n","import { createHash, createPrivateKey, createPublicKey, sign, verify } from 'node:crypto';\n\nexport interface RequestCanonicalInput {\n method: string;\n path: string;\n orgId?: string;\n body?: string | Buffer;\n timestamp: number;\n}\n\nexport interface SignRequestInput {\n method: string;\n path: string;\n orgId?: string;\n body?: string | Buffer;\n}\n\nexport interface VerifySignedRequestInput {\n method: string;\n path: string;\n orgId?: string;\n rawBody?: string | Buffer;\n timestamp: string | number;\n signature: string;\n publicKey: string;\n maxSkewSeconds?: number;\n}\n\n// Builds the canonical string signed for a control-plane request: METHOD\\npath\\norgId\\nsha256hex(body)\\ntimestamp\nexport function buildRequestCanonical(input: RequestCanonicalInput): string {\n const bodyHash = createHash('sha256')\n .update(input.body ?? '')\n .digest('hex');\n return [input.method.toUpperCase(), input.path, input.orgId ?? '', bodyHash, String(input.timestamp)].join('\\n');\n}\n\n// Signs a request with an Ed25519 private key (base64 pkcs8 DER), stamping the current unix time\nexport function signRequestHeaders(\n input: SignRequestInput,\n privateKeyBase64: string,\n): { 'x-timestamp': string; 'x-signature': string } {\n const timestamp = Math.floor(Date.now() / 1000);\n const canonical = buildRequestCanonical({ ...input, timestamp });\n const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, 'base64'), format: 'der', type: 'pkcs8' });\n const signature = sign(null, Buffer.from(canonical, 'utf8'), key).toString('base64');\n return { 'x-timestamp': String(timestamp), 'x-signature': signature };\n}\n\n// Verifies a signed request (signature + timestamp skew) against an Ed25519 public key; malformed input ⇒ false\nexport function verifySignedRequest(input: VerifySignedRequestInput): boolean {\n try {\n const timestamp = Number(input.timestamp);\n if (!Number.isFinite(timestamp)) return false;\n const maxSkew = input.maxSkewSeconds ?? 300;\n if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > maxSkew) return false;\n const canonical = buildRequestCanonical({\n method: input.method,\n path: input.path,\n orgId: input.orgId,\n body: input.rawBody,\n timestamp,\n });\n const key = createPublicKey({ key: Buffer.from(input.publicKey, 'base64'), format: 'der', type: 'spki' });\n return verify(null, Buffer.from(canonical, 'utf8'), key, Buffer.from(input.signature, 'base64'));\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;AACO,SAASA,mBAAmBC,OAAc;AAC/C,SAAOC,KAAKC,UAAUC,aAAaH,KAAAA,CAAAA;AACrC;AAFgBD;AAKhB,SAASI,aAAaH,OAAc;AAClC,MAAII,MAAMC,QAAQL,KAAAA,EAAQ,QAAOA,MAAMM,IAAIH,YAAAA;AAC3C,MAAIH,UAAU,QAAQ,OAAOA,UAAU,UAAU;AAC/C,UAAMO,SAASP;AACf,UAAMQ,SAAkC,CAAC;AACzC,eAAWC,OAAOC,OAAOC,KAAKJ,MAAAA,EAAQK,KAAI,EAAIJ,QAAOC,GAAAA,IAAON,aAAaI,OAAOE,GAAAA,CAAI;AACpF,WAAOD;EACT;AACA,SAAOR;AACT;AATSG;;;ACNT,SAASU,kBAAkBC,iBAAiBC,qBAAqBC,MAAMC,cAAc;AAS9E,SAASC,yBAAAA;AACd,QAAM,EAAEC,YAAYC,UAAS,IAAKC,oBAAoB,SAAA;AACtD,SAAO;IACLF,YAAYA,WAAWG,OAAO;MAAEC,MAAM;MAASC,QAAQ;IAAM,CAAA,EAAGC,SAAS,QAAA;IACzEL,WAAWA,UAAUE,OAAO;MAAEC,MAAM;MAAQC,QAAQ;IAAM,CAAA,EAAGC,SAAS,QAAA;EACxE;AACF;AANgBP;AAST,SAASQ,aAAgBC,SAAYC,kBAAwB;AAClE,QAAMC,MAAMC,iBAAiB;IAAED,KAAKE,OAAOC,KAAKJ,kBAAkB,QAAA;IAAWJ,QAAQ;IAAOD,MAAM;EAAQ,CAAA;AAC1G,QAAMU,YAAYC,KAAK,MAAMH,OAAOC,KAAKG,mBAAm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AASgB,oBAAoB7B,OAA+B;AACjE,MAAI;AACF,UAAMW,YAAYmB,OAAO9B,MAAMW,SAAS;AACxC,QAAI,CAACmB,OAAOC,SAASpB,SAAAA,EAAY,QAAO;AACxC,UAAMqB,UAAUhC,MAAMiC,kBAAkB;AACxC,QAAIlB,KAAKmB,IAAInB,KAAKC,MAAMC,KAAKC,IAAG,IAAK,GAAA,IAAQP,SAAAA,IAAaqB,QAAS,QAAO;AAC1E,UAAMb,YAAYpB,sBAAsB;MACtCO,QAAQN,MAAMM;MACdE,MAAMR,MAAMQ;MACZC,OAAOT,MAAMS;MACbL,MAAMJ,MAAMmC;MACZxB;IACF,CAAA;AACA,UAAMS,MAAMgB,iBAAgB;MAAEhB,KAAKE,OAAOC,KAAKvB,MAAMqC,WAAW,QAAA;MAAWb,QAAQ;MAAOC,MAAM;IAAO,CAAA;AACvG,WAAOa,QAAO,MAAMhB,OAAOC,KAAKJ,WAAW,MAAA,GAASC,KAAKE,OAAOC,KAAKvB,MAAM0B,WAAW,QAAA,CAAA;EACxF,QAAQ;AACN,WAAO;EACT;AACF;AAlBgBG;","names":["canonicalStringify","value","JSON","stringify","sortKeysDeep","Array","isArray","map","record","sorted","key","Object","keys","sort","createPrivateKey","createPublicKey","generateKeyPairSync","sign","verify","generateSigningKeyPair","privateKey","publicKey","generateKeyPairSync","export","type","format","toString","signDocument","payload","privateKeyBase64","key","createPrivateKey","Buffer","from","signature","sign","canonicalStringify","verifyDocument","doc","publicKeyBase64","createPublicKey","verify","createHash","createPrivateKey","createPublicKey","sign","verify","buildRequestCanonical","input","bodyHash","createHash","update","body","digest","method","toUpperCase","path","orgId","String","timestamp","join","signRequestHeaders","privateKeyBase64","Math","floor","Date","now","canonical","key","createPrivateKey","Buffer","from","format","type","signature","sign","toString","verifySignedRequest","Number","isFinite","maxSkew","maxSkewSeconds","abs","rawBody","createPublicKey","publicKey","verify"]}
|
|
@@ -9,12 +9,14 @@ interface PlatformDenyCodes {
|
|
|
9
9
|
mobile?: string[] | null;
|
|
10
10
|
}
|
|
11
11
|
type FeatureUnlocks = Record<string, PlatformCodes>;
|
|
12
|
-
type
|
|
12
|
+
type FeatureLocks = Record<string, PlatformDenyCodes>;
|
|
13
|
+
type SiteFeatureLocks = FeatureLocks;
|
|
13
14
|
interface SnapshotPermission {
|
|
14
15
|
code: string;
|
|
15
16
|
label: string;
|
|
16
17
|
isGlobal: boolean;
|
|
17
18
|
businesses: string[];
|
|
19
|
+
dependsOn: string[];
|
|
18
20
|
}
|
|
19
21
|
interface SnapshotMicrofrontendWeb {
|
|
20
22
|
code: string;
|
|
@@ -35,36 +37,59 @@ interface SnapshotMicrofrontends {
|
|
|
35
37
|
web?: SnapshotMicrofrontendWeb;
|
|
36
38
|
mobile?: SnapshotMicrofrontendMobile;
|
|
37
39
|
}
|
|
40
|
+
type ScopeType = 'ORG' | 'LE' | 'SITE_GROUP' | 'SITE';
|
|
41
|
+
type SiteType = 'OUTLET' | 'WAREHOUSE' | 'PRODUCTION';
|
|
42
|
+
declare const SITE_TYPES: SiteType[];
|
|
38
43
|
interface SnapshotFeature {
|
|
39
44
|
code: string;
|
|
40
45
|
name: string;
|
|
41
46
|
lucideIcon: string;
|
|
42
47
|
sfSymbol: string;
|
|
43
48
|
materialSymbol: string;
|
|
49
|
+
scope: ScopeType;
|
|
50
|
+
applicableSiteTypes: SiteType[];
|
|
44
51
|
permissions: SnapshotPermission[];
|
|
45
52
|
microfrontends: SnapshotMicrofrontends;
|
|
46
53
|
}
|
|
54
|
+
interface SnapshotAppFeatureRef {
|
|
55
|
+
code: string;
|
|
56
|
+
scope: ScopeType;
|
|
57
|
+
}
|
|
47
58
|
interface SnapshotApp {
|
|
48
59
|
code: string;
|
|
49
60
|
name: string;
|
|
50
61
|
icon: string;
|
|
51
62
|
sortOrder: number;
|
|
52
|
-
features:
|
|
63
|
+
features: SnapshotAppFeatureRef[];
|
|
53
64
|
}
|
|
54
65
|
interface SnapshotRoleTemplate {
|
|
55
66
|
name: string;
|
|
56
67
|
code: string;
|
|
68
|
+
scope: ScopeType;
|
|
69
|
+
siteType: SiteType;
|
|
57
70
|
features: FeatureUnlocks;
|
|
58
71
|
}
|
|
59
72
|
interface SnapshotPlan {
|
|
60
73
|
code: string;
|
|
61
74
|
name: string;
|
|
62
75
|
isCustom: boolean;
|
|
63
|
-
|
|
76
|
+
maxSites: number | null;
|
|
64
77
|
unlockedPermissions: FeatureUnlocks;
|
|
65
78
|
}
|
|
79
|
+
interface VocabularyEntry {
|
|
80
|
+
singular: string;
|
|
81
|
+
plural: string;
|
|
82
|
+
}
|
|
83
|
+
interface BusinessVocabulary {
|
|
84
|
+
site?: VocabularyEntry;
|
|
85
|
+
siteGroup?: VocabularyEntry;
|
|
86
|
+
outlet?: VocabularyEntry;
|
|
87
|
+
warehouse?: VocabularyEntry;
|
|
88
|
+
production?: VocabularyEntry;
|
|
89
|
+
}
|
|
66
90
|
interface SnapshotBusiness {
|
|
67
91
|
name: string;
|
|
92
|
+
vocabulary?: BusinessVocabulary;
|
|
68
93
|
apps: SnapshotApp[];
|
|
69
94
|
roleTemplates: Record<string, SnapshotRoleTemplate>;
|
|
70
95
|
plans: Record<string, SnapshotPlan>;
|
|
@@ -74,8 +99,9 @@ interface VersionSnapshot {
|
|
|
74
99
|
features: Record<string, SnapshotFeature>;
|
|
75
100
|
businesses: Record<string, SnapshotBusiness>;
|
|
76
101
|
}
|
|
77
|
-
declare
|
|
78
|
-
|
|
102
|
+
declare function snapshotFeatureKey(code: string, scope: ScopeType): string;
|
|
103
|
+
declare const SNAPSHOT_SCHEMA_VERSION = 2;
|
|
104
|
+
type LockReason = 'PLAN' | 'SITE';
|
|
79
105
|
interface CatalogPermission {
|
|
80
106
|
code: string;
|
|
81
107
|
locked: boolean;
|
|
@@ -110,4 +136,4 @@ interface FeatureCatalogEntry {
|
|
|
110
136
|
}
|
|
111
137
|
type RoleItem = SnapshotRoleTemplate;
|
|
112
138
|
|
|
113
|
-
export { type
|
|
139
|
+
export { type BusinessVocabulary as B, type CatalogPermission as C, type FeatureCatalogEntry as F, type LockReason as L, type PlatformBucket as P, type RoleItem as R, type ScopeType as S, type VersionSnapshot as V, type SiteType as a, type SiteFeatureLocks as b, type SnapshotFeature as c, type PlatformCodes as d, type FeatureUnlocks as e, type PlatformDenyCodes as f, type FeatureLocks as g, PLATFORMS as h, SITE_TYPES as i, SNAPSHOT_SCHEMA_VERSION as j, type SnapshotApp as k, type SnapshotAppFeatureRef as l, type VocabularyEntry as m, type SnapshotBusiness as n, type SnapshotMicrofrontendMobile as o, type SnapshotMicrofrontends as p, type SnapshotMicrofrontendWeb as q, type SnapshotPermission as r, type SnapshotPlan as s, type SnapshotRoleTemplate as t, snapshotFeatureKey as u };
|
|
@@ -9,12 +9,14 @@ interface PlatformDenyCodes {
|
|
|
9
9
|
mobile?: string[] | null;
|
|
10
10
|
}
|
|
11
11
|
type FeatureUnlocks = Record<string, PlatformCodes>;
|
|
12
|
-
type
|
|
12
|
+
type FeatureLocks = Record<string, PlatformDenyCodes>;
|
|
13
|
+
type SiteFeatureLocks = FeatureLocks;
|
|
13
14
|
interface SnapshotPermission {
|
|
14
15
|
code: string;
|
|
15
16
|
label: string;
|
|
16
17
|
isGlobal: boolean;
|
|
17
18
|
businesses: string[];
|
|
19
|
+
dependsOn: string[];
|
|
18
20
|
}
|
|
19
21
|
interface SnapshotMicrofrontendWeb {
|
|
20
22
|
code: string;
|
|
@@ -35,36 +37,59 @@ interface SnapshotMicrofrontends {
|
|
|
35
37
|
web?: SnapshotMicrofrontendWeb;
|
|
36
38
|
mobile?: SnapshotMicrofrontendMobile;
|
|
37
39
|
}
|
|
40
|
+
type ScopeType = 'ORG' | 'LE' | 'SITE_GROUP' | 'SITE';
|
|
41
|
+
type SiteType = 'OUTLET' | 'WAREHOUSE' | 'PRODUCTION';
|
|
42
|
+
declare const SITE_TYPES: SiteType[];
|
|
38
43
|
interface SnapshotFeature {
|
|
39
44
|
code: string;
|
|
40
45
|
name: string;
|
|
41
46
|
lucideIcon: string;
|
|
42
47
|
sfSymbol: string;
|
|
43
48
|
materialSymbol: string;
|
|
49
|
+
scope: ScopeType;
|
|
50
|
+
applicableSiteTypes: SiteType[];
|
|
44
51
|
permissions: SnapshotPermission[];
|
|
45
52
|
microfrontends: SnapshotMicrofrontends;
|
|
46
53
|
}
|
|
54
|
+
interface SnapshotAppFeatureRef {
|
|
55
|
+
code: string;
|
|
56
|
+
scope: ScopeType;
|
|
57
|
+
}
|
|
47
58
|
interface SnapshotApp {
|
|
48
59
|
code: string;
|
|
49
60
|
name: string;
|
|
50
61
|
icon: string;
|
|
51
62
|
sortOrder: number;
|
|
52
|
-
features:
|
|
63
|
+
features: SnapshotAppFeatureRef[];
|
|
53
64
|
}
|
|
54
65
|
interface SnapshotRoleTemplate {
|
|
55
66
|
name: string;
|
|
56
67
|
code: string;
|
|
68
|
+
scope: ScopeType;
|
|
69
|
+
siteType: SiteType;
|
|
57
70
|
features: FeatureUnlocks;
|
|
58
71
|
}
|
|
59
72
|
interface SnapshotPlan {
|
|
60
73
|
code: string;
|
|
61
74
|
name: string;
|
|
62
75
|
isCustom: boolean;
|
|
63
|
-
|
|
76
|
+
maxSites: number | null;
|
|
64
77
|
unlockedPermissions: FeatureUnlocks;
|
|
65
78
|
}
|
|
79
|
+
interface VocabularyEntry {
|
|
80
|
+
singular: string;
|
|
81
|
+
plural: string;
|
|
82
|
+
}
|
|
83
|
+
interface BusinessVocabulary {
|
|
84
|
+
site?: VocabularyEntry;
|
|
85
|
+
siteGroup?: VocabularyEntry;
|
|
86
|
+
outlet?: VocabularyEntry;
|
|
87
|
+
warehouse?: VocabularyEntry;
|
|
88
|
+
production?: VocabularyEntry;
|
|
89
|
+
}
|
|
66
90
|
interface SnapshotBusiness {
|
|
67
91
|
name: string;
|
|
92
|
+
vocabulary?: BusinessVocabulary;
|
|
68
93
|
apps: SnapshotApp[];
|
|
69
94
|
roleTemplates: Record<string, SnapshotRoleTemplate>;
|
|
70
95
|
plans: Record<string, SnapshotPlan>;
|
|
@@ -74,8 +99,9 @@ interface VersionSnapshot {
|
|
|
74
99
|
features: Record<string, SnapshotFeature>;
|
|
75
100
|
businesses: Record<string, SnapshotBusiness>;
|
|
76
101
|
}
|
|
77
|
-
declare
|
|
78
|
-
|
|
102
|
+
declare function snapshotFeatureKey(code: string, scope: ScopeType): string;
|
|
103
|
+
declare const SNAPSHOT_SCHEMA_VERSION = 2;
|
|
104
|
+
type LockReason = 'PLAN' | 'SITE';
|
|
79
105
|
interface CatalogPermission {
|
|
80
106
|
code: string;
|
|
81
107
|
locked: boolean;
|
|
@@ -110,4 +136,4 @@ interface FeatureCatalogEntry {
|
|
|
110
136
|
}
|
|
111
137
|
type RoleItem = SnapshotRoleTemplate;
|
|
112
138
|
|
|
113
|
-
export { type
|
|
139
|
+
export { type BusinessVocabulary as B, type CatalogPermission as C, type FeatureCatalogEntry as F, type LockReason as L, type PlatformBucket as P, type RoleItem as R, type ScopeType as S, type VersionSnapshot as V, type SiteType as a, type SiteFeatureLocks as b, type SnapshotFeature as c, type PlatformCodes as d, type FeatureUnlocks as e, type PlatformDenyCodes as f, type FeatureLocks as g, PLATFORMS as h, SITE_TYPES as i, SNAPSHOT_SCHEMA_VERSION as j, type SnapshotApp as k, type SnapshotAppFeatureRef as l, type VocabularyEntry as m, type SnapshotBusiness as n, type SnapshotMicrofrontendMobile as o, type SnapshotMicrofrontends as p, type SnapshotMicrofrontendWeb as q, type SnapshotPermission as r, type SnapshotPlan as s, type SnapshotRoleTemplate as t, snapshotFeatureKey as u };
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/index.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/index.ts"],"sourcesContent":["export type { ApiErrorResponse, FieldError, ProblemDetails } from './error-response.types';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;","names":[]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface FieldError {
|
|
2
|
+
field: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
interface ProblemDetails {
|
|
6
|
+
type: string;
|
|
7
|
+
title: string;
|
|
8
|
+
status: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
detail: string;
|
|
11
|
+
instance?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ApiErrorResponse extends ProblemDetails {
|
|
14
|
+
errors: FieldError[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { ApiErrorResponse, FieldError, ProblemDetails };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface FieldError {
|
|
2
|
+
field: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
interface ProblemDetails {
|
|
6
|
+
type: string;
|
|
7
|
+
title: string;
|
|
8
|
+
status: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
detail: string;
|
|
11
|
+
instance?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ApiErrorResponse extends ProblemDetails {
|
|
14
|
+
errors: FieldError[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type { ApiErrorResponse, FieldError, ProblemDetails };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|