@ksevendev/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,318 @@
1
+ export type WebSdkPlatform = 'nodejs' | 'php' | 'wordpress' | 'universal';
2
+ export type WebSdkChannel = 'stable' | 'beta';
3
+ export type WebSdkEnvironment = 'production' | 'staging' | 'development';
4
+ export interface WebKeyTransitionProof {
5
+ schema: 'k7web-key-transition|v1';
6
+ fromKeyId: string;
7
+ fromKeyVersion: number;
8
+ toKeyId: string;
9
+ toKeyVersion: number;
10
+ toPublicKeyRawHex: string;
11
+ issuedAt: string;
12
+ expiresAt: string;
13
+ reason: string;
14
+ signatureBase64: string;
15
+ }
16
+ export interface WebSigningKeyEntry {
17
+ keyId: string;
18
+ role: 'ACTIVE' | 'SECONDARY' | 'RETIRED';
19
+ keyVersion: number;
20
+ algorithm: 'Ed25519';
21
+ publicKeyPem: string;
22
+ publicKeyRawHex: string;
23
+ rootProof: WebKeyTransitionProof | null;
24
+ transitionProof: WebKeyTransitionProof | null;
25
+ createdAt?: string;
26
+ rotatedAt?: string | null;
27
+ expiresAt?: string | null;
28
+ }
29
+ export interface WebPublicKeyBundle {
30
+ schema: 'k7-web-keys-v1';
31
+ algorithm: 'Ed25519';
32
+ protocolVersion: string;
33
+ rootKey: {
34
+ keyId: string;
35
+ algorithm: 'Ed25519';
36
+ publicKeyPem: string;
37
+ publicKeyRawHex: string;
38
+ mode?: string;
39
+ };
40
+ activeKey: WebSigningKeyEntry;
41
+ secondaryKeys: WebSigningKeyEntry[];
42
+ keys: WebSigningKeyEntry[];
43
+ issuedAt: string;
44
+ }
45
+ export interface WebRuntimeSignatureEnvelope {
46
+ schema: 'k7-web-response-sig-v1';
47
+ protocolVersion: string;
48
+ algorithm: 'Ed25519';
49
+ keyId: string;
50
+ keyVersion: number;
51
+ rootKeyId: string;
52
+ requestId: string;
53
+ nonce: string;
54
+ method: string;
55
+ path: string;
56
+ timestamp: string;
57
+ httpStatus: number;
58
+ decision: 'ALLOW' | 'DENY';
59
+ code: string;
60
+ productSlug: string | null;
61
+ licenseId: number | null;
62
+ installationId: string | null;
63
+ domain: string | null;
64
+ licenseStatus: string | null;
65
+ expiresAt: string | null;
66
+ entitlementHash: string | null;
67
+ payloadSha256: string;
68
+ signatureBase64: string;
69
+ }
70
+ export interface WebEcdhHandshakeSignature {
71
+ schema: 'k7-web-ecdh-sig-v1';
72
+ algorithm: 'Ed25519';
73
+ keyId: string;
74
+ keyVersion: number;
75
+ rootKeyId: string;
76
+ timestamp: string;
77
+ nonce: string;
78
+ signatureBase64: string;
79
+ publicKeyPem: string;
80
+ publicKeyRawHex: string;
81
+ rootProof: WebKeyTransitionProof | null;
82
+ transitionProof: WebKeyTransitionProof | null;
83
+ }
84
+ export type WebSdkReleaseKind = 'PRODUCT' | 'UPDATE' | 'PLUGIN';
85
+ export type WebSdkDomainEnvironment = 'PRODUCTION' | 'STAGING' | 'TEST';
86
+ export type WebSdkLicenseKind = 'FREE' | 'TRIAL' | 'ONE_TIME' | 'SUBSCRIPTION' | 'LIFETIME';
87
+ export interface WebOfflineValidationPolicy {
88
+ allowed: boolean;
89
+ gracePeriodHours: number;
90
+ graceUntil: string | null;
91
+ hardRevokeStatuses?: string[];
92
+ maxOfflineDays?: number;
93
+ }
94
+ export interface WebSdkPersistedState {
95
+ apiBaseUrl: string;
96
+ installationId: string;
97
+ installationCredential: string;
98
+ credentialPrefix?: string;
99
+ credentialVersion?: number;
100
+ domain: string;
101
+ platform: WebSdkPlatform;
102
+ appVersion: string;
103
+ environment: string;
104
+ instanceFingerprint: string;
105
+ installedAt: string;
106
+ updatedAt: string;
107
+ pinnedPublicKeys?: Record<string, string>;
108
+ pinnedRootPublicKeyPem?: string;
109
+ clientPublicKeyPem?: string;
110
+ clientPrivateKeyPem?: string;
111
+ requireSealedTransport?: boolean;
112
+ protocolVersion?: string;
113
+ lastValidatedAt?: string;
114
+ graceUntil?: string | null;
115
+ lastSignedEntitlement?: Record<string, any> | null;
116
+ lastSignedValidationResponse?: Record<string, any> | null;
117
+ }
118
+ export interface WebSdkStateStore {
119
+ read: () => Promise<WebSdkPersistedState | null>;
120
+ write: (state: WebSdkPersistedState | null) => Promise<void>;
121
+ }
122
+ export interface KSevenWebSdkConfig {
123
+ apiBaseUrl: string;
124
+ /** Caminho do arquivo local cifrado (padrão: .kseven-web-license.dat) */
125
+ stateFilePath?: string;
126
+ platform?: WebSdkPlatform;
127
+ timeoutMs?: number;
128
+ /** Permite HTTP sem TLS apenas em desenvolvimento/testes locais */
129
+ allowInsecureLocalHttp?: boolean;
130
+ /** Chave/segredo adicional para cifrar o estado local (AES-256-GCM). Se omitido, deriva chave vinculada ao host. */
131
+ stateSecret?: string;
132
+ /** Habilita envelope cifrado ECDH P-256 + AES-256-GCM em trânsito (padrão: true). */
133
+ useEncryptedTransport?: boolean;
134
+ /** Quando true, falha fechado se a negociação ECDH k7seal.v1 não puder ser concluída. */
135
+ requireSealedTransport?: boolean;
136
+ /** Chave pública raiz Ed25519 pinada do domínio web para validar cadeia ativa/secundária e assinaturas de runtime. */
137
+ pinnedRootPublicKeyPem?: string;
138
+ /** Verifica signatureEnvelope Ed25519 em respostas ALLOW/DENY e handshake ECDH (padrão: true). */
139
+ verifyResponseSignatures?: boolean;
140
+ /** Chave(s) pública(s) Ed25519 pinadas por keyId (opcional; caso omitido busca /keys) */
141
+ pinnedPublicKeys?: Record<string, string>;
142
+ /** Chave pública/privada Ed25519 opcional da instalação para assinatura assimétrica de requisições. */
143
+ clientPublicKeyPem?: string;
144
+ clientPrivateKeyPem?: string;
145
+ /** Persistência customizada (ex.: banco/cofre) em substituição ao arquivo local */
146
+ stateStore?: WebSdkStateStore;
147
+ }
148
+ export interface InstallOptions {
149
+ licenseKey: string;
150
+ domain: string;
151
+ appVersion: string;
152
+ platform?: WebSdkPlatform;
153
+ environment?: WebSdkEnvironment;
154
+ instanceFingerprint?: string;
155
+ idempotencyKey?: string;
156
+ /** Gera automaticamente par Ed25519 por instalação e registra a chave pública no servidor. */
157
+ generateClientKeyPair?: boolean;
158
+ clientPublicKeyPem?: string;
159
+ clientPrivateKeyPem?: string;
160
+ /** Exige transporte selado k7seal.v1 para esta instalação no servidor. */
161
+ requireSealedTransport?: boolean;
162
+ }
163
+ export interface ValidateOptions {
164
+ /** Quando true, permite validar localmente usando o último entitlement assinado dentro do graceUntil em caso de falha de rede/503. */
165
+ allowOfflineGrace?: boolean;
166
+ /** Timestamp customizado em ms (útil para testes). */
167
+ nowMs?: number;
168
+ }
169
+ export interface OfflineValidationResult {
170
+ valid: boolean;
171
+ offline: true;
172
+ inGracePeriod: boolean;
173
+ graceUntil: string;
174
+ lastValidatedAt: string | null;
175
+ installationId: string;
176
+ domain: string;
177
+ entitlement: Record<string, any>;
178
+ signatureKeyId: string;
179
+ }
180
+ export interface TransferInstallationOptions {
181
+ toDomain: string;
182
+ reason?: string;
183
+ immediateActivate?: boolean;
184
+ platform?: WebSdkPlatform;
185
+ appVersion?: string;
186
+ instanceFingerprint?: string;
187
+ clientPublicKeyPem?: string;
188
+ requireSealedTransport?: boolean;
189
+ }
190
+ export interface CheckVersionOptions {
191
+ channel?: WebSdkChannel;
192
+ currentVersion?: string;
193
+ releaseKind?: WebSdkReleaseKind;
194
+ }
195
+ export interface ReleaseSummary {
196
+ releaseId: number;
197
+ productSlug: string;
198
+ version: string;
199
+ channel: WebSdkChannel;
200
+ platform: string;
201
+ releaseKind?: WebSdkReleaseKind;
202
+ minCompatibleVersion: string | null;
203
+ maxCompatibleVersion?: string | null;
204
+ allowRollback?: boolean;
205
+ requiredAddonCodes?: string[];
206
+ changelog: string;
207
+ packageSizeBytes: number;
208
+ packageSha256: string;
209
+ manifestJson: string;
210
+ manifestSignature: string;
211
+ signingKeyId: string;
212
+ publicKeyPem?: string;
213
+ publishedAt: string | null;
214
+ }
215
+ export interface UpdateOptions {
216
+ channel?: WebSdkChannel;
217
+ currentVersion?: string;
218
+ releaseKind?: WebSdkReleaseKind;
219
+ destDir?: string;
220
+ downloadFileName?: string;
221
+ /** Handler opcional para aplicar pacote verificado (ex.: extração/restart) */
222
+ onVerifiedPackage?: (ctx: {
223
+ packageBuffer: Buffer;
224
+ release: ReleaseSummary;
225
+ verifiedSha256: string;
226
+ }) => Promise<void>;
227
+ }
228
+ export interface RollbackOptions {
229
+ channel?: WebSdkChannel;
230
+ destDir?: string;
231
+ downloadFileName?: string;
232
+ onVerifiedPackage?: UpdateOptions['onVerifiedPackage'];
233
+ }
234
+ export interface CheckVersionResult {
235
+ updateAvailable: boolean;
236
+ channel: WebSdkChannel;
237
+ currentVersion: string;
238
+ latestRelease: ReleaseSummary | null;
239
+ availableRollbacks?: ReleaseSummary[];
240
+ updatesActive?: boolean;
241
+ updatesExpiresAt?: string | null;
242
+ signatureVerified: boolean;
243
+ }
244
+ export interface UpdateResult {
245
+ updated: boolean;
246
+ previousVersion: string;
247
+ currentVersion: string;
248
+ release: ReleaseSummary | null;
249
+ savedFilePath?: string;
250
+ verifiedSha256?: string;
251
+ signatureVerified: boolean;
252
+ rollback?: boolean;
253
+ }
254
+ export interface AutoUpdateMigration {
255
+ id: string;
256
+ run: (ctx: {
257
+ targetDir: string;
258
+ fromVersion: string;
259
+ toVersion: string;
260
+ }) => Promise<void>;
261
+ }
262
+ export interface AutoUpdateOptions {
263
+ channel?: WebSdkChannel;
264
+ currentVersion?: string;
265
+ releaseKind?: WebSdkReleaseKind;
266
+ /** Diretório raiz da aplicação alvo a ser atualizado de forma transacional. */
267
+ targetDir: string;
268
+ /** Diretório opcional para backup pré-atualização (padrão: sibling temp backup dir). */
269
+ backupDir?: string;
270
+ /** Caminhos relativos preservados durante a aplicação (ex.: ['.env', '.kseven-web-license.dat']). */
271
+ preserveRelativePaths?: string[];
272
+ /** Função que extrai/aplica o pacote verificado no diretório temporário ou alvo. */
273
+ applyPackage: (ctx: {
274
+ stagingPackagePath: string;
275
+ packageBuffer: Buffer;
276
+ targetDir: string;
277
+ release: ReleaseSummary;
278
+ verifiedSha256: string;
279
+ }) => Promise<void>;
280
+ /** Migrações tipadas declaradas executadas em ordem após aplicação; erro aciona rollback completo. */
281
+ migrations?: AutoUpdateMigration[];
282
+ /** Reporta progresso e resultado para o painel via /updates/auto-update/report (padrão: true). */
283
+ reportProgress?: boolean;
284
+ }
285
+ export interface AutoUpdateResult {
286
+ runUid: string;
287
+ updated: boolean;
288
+ status: 'UP_TO_DATE' | 'COMPLETED' | 'ROLLED_BACK' | 'FAILED';
289
+ previousVersion: string;
290
+ currentVersion: string;
291
+ targetVersion: string | null;
292
+ release: ReleaseSummary | null;
293
+ signatureVerified: boolean;
294
+ sha256Verified: boolean;
295
+ backupCreated: boolean;
296
+ rollbackPerformed: boolean;
297
+ migrationsExecuted: string[];
298
+ sanitizedError: string | null;
299
+ }
300
+ export interface VerifiedManifestPayload {
301
+ schema: string;
302
+ webProductId: number;
303
+ productSlug: string;
304
+ channel: string;
305
+ platform: string;
306
+ version: string;
307
+ minCompatibleVersion: string | null;
308
+ packageSha256: string;
309
+ packageSizeBytes: number;
310
+ issuedAt: string;
311
+ }
312
+ export declare class KSevenWebSdkError extends Error {
313
+ readonly statusCode: number;
314
+ readonly code: string;
315
+ readonly requestId?: string;
316
+ readonly details?: Record<string, any>;
317
+ constructor(statusCode: number, code: string, message: string, requestId?: string, details?: Record<string, any>);
318
+ }
package/dist/types.js ADDED
@@ -0,0 +1,16 @@
1
+ export class KSevenWebSdkError extends Error {
2
+ statusCode;
3
+ code;
4
+ requestId;
5
+ details;
6
+ constructor(statusCode, code, message, requestId, details) {
7
+ super(message);
8
+ this.name = 'KSevenWebSdkError';
9
+ this.statusCode = statusCode;
10
+ this.code = code;
11
+ if (requestId)
12
+ this.requestId = requestId;
13
+ if (details)
14
+ this.details = details;
15
+ }
16
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@ksevendev/sdk",
3
+ "version": "1.0.0",
4
+ "description": "SDK oficial servidor-side (Node.js / TypeScript) para Licenciamento Web K'Seven com transporte cifrado ECDH+AES-256-GCM e estado criptografado.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "bin": {
16
+ "k7web": "dist/cli.js"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "README.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.json",
25
+ "prepack": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "kseven",
29
+ "licensing",
30
+ "drm",
31
+ "web-sdk",
32
+ "aes-256-gcm",
33
+ "ed25519"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18.18.0"
37
+ }
38
+ }