@tvip2/sdk 0.1.0-beta.1

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/LICENSE ADDED
@@ -0,0 +1,43 @@
1
+ VELA TVIP SDK — Licence Proprietaire
2
+
3
+ Copyright (c) 2026 Missylia Systems. Tous droits reserves.
4
+
5
+ BREVET EN COURS DE DEPOT — PATENT PENDING
6
+
7
+ Ce logiciel et sa documentation sont la propriete exclusive de Missylia Systems.
8
+ L'acces a ce SDK est strictement reserve aux participants du programme beta
9
+ autorise par Missylia Systems.
10
+
11
+ CONDITIONS D'UTILISATION :
12
+
13
+ 1. ACCES RESTREINT — Ce SDK est distribue en beta fermee. Toute utilisation
14
+ necessite une cle API valide fournie par Missylia Systems.
15
+
16
+ 2. INTERDICTION DE REDISTRIBUTION — Vous ne pouvez pas copier, redistribuer,
17
+ sous-licencier, vendre ou rendre disponible ce SDK a des tiers sans
18
+ l'autorisation ecrite prealable de Missylia Systems.
19
+
20
+ 3. INTERDICTION DE RETRO-INGENIERIE — Vous ne pouvez pas decompiler,
21
+ desassembler ou tenter d'extraire le code source, les algorithmes ou
22
+ les methodes du protocole TVIP.
23
+
24
+ 4. PROPRIETE INTELLECTUELLE — Le protocole TVIP (Transaction-to-Verified-
25
+ Invoice Protocol), ses algorithmes de correlation, de signature
26
+ cryptographique SHA-256, et de rapprochement bancaire automatique sont
27
+ proteges par un brevet en cours de depot par Missylia Systems.
28
+
29
+ 5. CONFIDENTIALITE — Les informations techniques contenues dans ce SDK
30
+ sont confidentielles. Vous vous engagez a ne pas divulguer ces
31
+ informations a des tiers.
32
+
33
+ 6. SANS GARANTIE — Ce SDK est fourni "en l'etat", sans garantie d'aucune
34
+ sorte, expresse ou implicite.
35
+
36
+ 7. RESILIATION — Missylia Systems se reserve le droit de revoquer l'acces
37
+ a tout moment, sans preavis.
38
+
39
+ Pour toute demande d'acces au programme beta :
40
+ contact@missylia.com
41
+
42
+ Missylia Systems — VELA — Transaction-to-Verified-Invoice Protocol (TVIP)
43
+ Patent Pending — Brevet en cours de depot
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @tvip2/sdk — Beta Fermee
2
+
3
+ > **BREVET EN COURS DE DEPOT — PATENT PENDING**
4
+ >
5
+ > Ce SDK est distribue en beta fermee. L'acces necessite une invitation
6
+ > et une cle API valide fournie par Missylia Systems.
7
+
8
+ SDK officiel JavaScript/Node.js pour le **protocole TVIP** (Transaction-to-Verified-Invoice Protocol).
9
+
10
+ Correle les autorisations de paiement avec les factures marchands detaillees en temps reel.
11
+
12
+ ## Acces Beta
13
+
14
+ Ce SDK n'est pas disponible publiquement. Pour demander l'acces :
15
+
16
+ - Email : contact@missylia.com
17
+ - Sujet : "Demande acces SDK TVIP Beta"
18
+
19
+ ## Installation (participants beta uniquement)
20
+
21
+ ```bash
22
+ npm install @tvip2/sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```javascript
28
+ const { TVIP } = require('@tvip2/sdk');
29
+
30
+ // Cle API fournie par VELA Protocol
31
+ const tvip = new TVIP({ apiKey: 'sk_beta_votre_cle' });
32
+
33
+ // 1. Creer une session de correlation
34
+ const session = await tvip.createSession({
35
+ amount: 12450, // centimes
36
+ currency: 'EUR',
37
+ merchant_order_id: 'ord_1001'
38
+ });
39
+
40
+ // 2. Envoyer la facture depuis le POS
41
+ await tvip.sendInvoice({
42
+ correlation_token: session.correlation_token,
43
+ invoice_id: 'inv_1001',
44
+ items: [
45
+ { name: 'Tomates bio', quantity: 4, unit_price: 2500, tax_rate: 0.055 },
46
+ { name: 'Pain complet', quantity: 1, unit_price: 2450, tax_rate: 0.055 },
47
+ ],
48
+ total: 12450,
49
+ currency: 'EUR'
50
+ });
51
+
52
+ // 3. TVIP cree automatiquement un evenement verifie :
53
+ // -> Signe SHA-256
54
+ // -> Ecritures comptables (PCG)
55
+ // -> Rapprochement bancaire
56
+ // -> Categorisation IA
57
+ ```
58
+
59
+ ## AI Vision Scanner
60
+
61
+ ```javascript
62
+ const fs = require('fs');
63
+ const image = fs.readFileSync('./ticket.jpg', 'base64');
64
+
65
+ const parsed = await tvip.scanImage(image);
66
+ // Retourne : {merchant, items, total, tax, ...}
67
+ ```
68
+
69
+ ## Verification Webhook
70
+
71
+ ```javascript
72
+ const { TVIP } = require('@tvip2/sdk');
73
+
74
+ app.post('/webhooks/tvip', (req, res) => {
75
+ const isValid = TVIP.verifyWebhook(
76
+ JSON.stringify(req.body),
77
+ req.headers['x-tvip-signature'],
78
+ process.env.TVIP_WEBHOOK_SECRET
79
+ );
80
+ if (!isValid) return res.status(401).send('Signature invalide');
81
+ // Traiter l'evenement...
82
+ });
83
+ ```
84
+
85
+ ## API Reference
86
+
87
+ | Methode | Description |
88
+ |---------|-------------|
89
+ | `createSession(params)` | Creer une session de correlation |
90
+ | `getSession(token)` | Obtenir session par token |
91
+ | `sendInvoice(params)` | Envoyer facture marchande |
92
+ | `getEvent(id)` | Obtenir evenement TVIP |
93
+ | `listEvents(filters?)` | Lister evenements avec filtres |
94
+ | `ingest({ source, data })` | Ingerer Factur-X/JSON/XML |
95
+ | `scanImage(base64)` | Scanner ticket IA Vision |
96
+ | `TVIP.verifyWebhook(...)` | Verifier signature HMAC-SHA256 |
97
+
98
+ ## Licence
99
+
100
+ Licence proprietaire — Missylia Systems
101
+ Brevet en cours de depot (Patent Pending)
102
+ Voir fichier LICENSE pour les conditions d'utilisation.
103
+
104
+ (c) 2026 Missylia Systems. Tous droits reserves.
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@tvip2/sdk",
3
+ "version": "0.1.0-beta.1",
4
+ "description": "TVIP SDK — Transaction-to-Verified-Invoice Protocol. Beta fermee — brevet en cours de depot.",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "files": ["src/", "README.md", "LICENSE"],
8
+ "keywords": ["tvip", "payment", "invoice", "correlation", "fintech"],
9
+ "author": "Missylia Systems <contact@missylia.com>",
10
+ "license": "SEE LICENSE IN LICENSE",
11
+ "private": false,
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/vela-protocol/tvip-sdk-js"
18
+ },
19
+ "engines": { "node": ">=18.0.0" }
20
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ export class TVIPError extends Error {
2
+ status: number;
3
+ code?: string;
4
+ constructor(message: string, status?: number, code?: string);
5
+ }
6
+
7
+ export interface TVIPConfig {
8
+ apiKey: string;
9
+ baseUrl?: string;
10
+ timeout?: number;
11
+ }
12
+
13
+ export interface SessionParams {
14
+ amount: number;
15
+ currency: string;
16
+ merchant_order_id?: string;
17
+ }
18
+
19
+ export interface InvoiceItem {
20
+ name: string;
21
+ quantity: number;
22
+ unit_price: number;
23
+ tax_rate: number;
24
+ }
25
+
26
+ export interface InvoiceParams {
27
+ correlation_token: string;
28
+ invoice_id: string;
29
+ items: InvoiceItem[];
30
+ total: number;
31
+ currency: string;
32
+ }
33
+
34
+ export interface EventFilters {
35
+ status?: string;
36
+ limit?: number;
37
+ offset?: number;
38
+ }
39
+
40
+ export interface IngestParams {
41
+ source: 'facturx' | 'json' | 'xml';
42
+ data: any;
43
+ }
44
+
45
+ export class TVIP {
46
+ isSandbox: boolean;
47
+ constructor(config: TVIPConfig);
48
+ createSession(params: SessionParams): Promise<any>;
49
+ getSession(correlationToken: string): Promise<any>;
50
+ sendInvoice(params: InvoiceParams): Promise<any>;
51
+ getEvent(eventId: string): Promise<any>;
52
+ listEvents(filters?: EventFilters): Promise<any>;
53
+ ingest(params: IngestParams): Promise<any>;
54
+ scanImage(base64Image: string): Promise<any>;
55
+ static verifyWebhook(payload: string, signature: string, secret: string): boolean;
56
+ }
package/src/index.js ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * TVIP SDK — Transaction-to-Verified-Invoice Protocol
3
+ * JavaScript/Node.js Client
4
+ */
5
+
6
+ class TVIPError extends Error {
7
+ constructor(message, status, code) {
8
+ super(message);
9
+ this.name = 'TVIPError';
10
+ this.status = status;
11
+ this.code = code;
12
+ }
13
+ }
14
+
15
+ class TVIP {
16
+ /**
17
+ * @param {Object} config
18
+ * @param {string} config.apiKey - API key (sk_test_* or sk_live_*)
19
+ * @param {string} [config.baseUrl] - Base URL (default: https://api.tvip.com)
20
+ * @param {number} [config.timeout] - Request timeout in ms (default: 30000)
21
+ */
22
+ constructor({ apiKey, baseUrl = 'https://api.tvip.com', timeout = 30000 }) {
23
+ if (!apiKey) throw new TVIPError('API key is required');
24
+ this.apiKey = apiKey;
25
+ this.baseUrl = baseUrl.replace(/\/$/, '');
26
+ this.timeout = timeout;
27
+ this.isSandbox = apiKey.startsWith('sk_test_');
28
+ }
29
+
30
+ async _request(method, path, body = null) {
31
+ const url = `${this.baseUrl}/sdk/v2${path}`;
32
+ const opts = {
33
+ method,
34
+ headers: {
35
+ 'Authorization': `Bearer ${this.apiKey}`,
36
+ 'Content-Type': 'application/json',
37
+ 'X-TVIP-SDK': 'js/0.1.0',
38
+ },
39
+ };
40
+ if (body) opts.body = JSON.stringify(body);
41
+
42
+ const controller = new AbortController();
43
+ const timer = setTimeout(() => controller.abort(), this.timeout);
44
+ opts.signal = controller.signal;
45
+
46
+ try {
47
+ const res = await fetch(url, opts);
48
+ const data = await res.json();
49
+ if (!res.ok) throw new TVIPError(data.detail || data.message || 'API Error', res.status, data.code);
50
+ return data;
51
+ } finally {
52
+ clearTimeout(timer);
53
+ }
54
+ }
55
+
56
+ // ─── Sessions ───
57
+ /**
58
+ * Create a TVIP correlation session
59
+ * @param {Object} params
60
+ * @param {number} params.amount - Amount in cents
61
+ * @param {string} params.currency - ISO 4217 currency code
62
+ * @param {string} [params.merchant_order_id] - Merchant order reference
63
+ * @returns {Promise<Object>} Session with correlation_token
64
+ */
65
+ async createSession({ amount, currency, merchant_order_id }) {
66
+ return this._request('POST', '/sessions', { amount, currency, merchant_order_id });
67
+ }
68
+
69
+ /**
70
+ * Get session by correlation token
71
+ * @param {string} correlationToken
72
+ */
73
+ async getSession(correlationToken) {
74
+ return this._request('GET', `/sessions/${correlationToken}`);
75
+ }
76
+
77
+ // ─── Invoices ───
78
+ /**
79
+ * Send a detailed merchant invoice
80
+ * @param {Object} params
81
+ * @param {string} params.correlation_token
82
+ * @param {string} params.invoice_id
83
+ * @param {Array} params.items - [{name, quantity, unit_price, tax_rate}]
84
+ * @param {number} params.total - Total in cents
85
+ * @param {string} params.currency
86
+ */
87
+ async sendInvoice({ correlation_token, invoice_id, items, total, currency }) {
88
+ return this._request('POST', '/invoices', { correlation_token, invoice_id, items, total, currency });
89
+ }
90
+
91
+ // ─── Events ───
92
+ /**
93
+ * Get TVIP event by ID
94
+ * @param {string} eventId
95
+ */
96
+ async getEvent(eventId) {
97
+ return this._request('GET', `/events/${eventId}`);
98
+ }
99
+
100
+ /**
101
+ * List TVIP events with optional filters
102
+ * @param {Object} [filters]
103
+ * @param {string} [filters.status]
104
+ * @param {number} [filters.limit]
105
+ * @param {number} [filters.offset]
106
+ */
107
+ async listEvents(filters = {}) {
108
+ const qs = new URLSearchParams(filters).toString();
109
+ return this._request('GET', `/events${qs ? '?' + qs : ''}`);
110
+ }
111
+
112
+ // ─── Ingestion ───
113
+ /**
114
+ * Ingest an invoice (Factur-X, JSON, XML)
115
+ * @param {Object} params
116
+ * @param {string} params.source - 'facturx' | 'json' | 'xml'
117
+ * @param {*} params.data - Invoice data
118
+ */
119
+ async ingest({ source, data }) {
120
+ return this._request('POST', '/ingest', { source, data });
121
+ }
122
+
123
+ /**
124
+ * Scan invoice image with AI Vision
125
+ * @param {string} base64Image - Base64 encoded image
126
+ */
127
+ async scanImage(base64Image) {
128
+ return this._request('POST', '/ingest/scan', { image: base64Image });
129
+ }
130
+
131
+ // ─── Webhooks ───
132
+ /**
133
+ * Verify webhook signature (HMAC-SHA256)
134
+ * @param {string} payload - Raw request body
135
+ * @param {string} signature - X-TVIP-Signature header
136
+ * @param {string} secret - Webhook secret
137
+ * @returns {boolean}
138
+ */
139
+ static verifyWebhook(payload, signature, secret) {
140
+ const crypto = require('crypto');
141
+ const expected = crypto.createHmac('sha256', secret).update(payload).digest('hex');
142
+ return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
143
+ }
144
+ }
145
+
146
+ module.exports = { TVIP, TVIPError };