Paigaldamine
Chaindoc SDK-de täielik installimisjuhend. Seadistage Server SDK tagapõhja integreerimiseks ja Embed SDK esipõhja allkirjastamise liidese jaoks.
Eeltingimused
Serveri SDK installimine
Server SDK-d kasutatakse tagapõhja integreerimiseks – dokumentide haldamiseks, allkirja taotlemiseks ja plokiahela kontrollimiseks.
1. samm: Paigalda pakett
npm install @chaindoc_io/server-sdk2. samm: konfigureerige keskkonnamuutujad
Loo oma projekti juurkataloogis .env-fail:
# Production keys
CHAINDOC_SECRET_KEY=sk_live_xxxxxxxxxxxxx
# Staging/Testing keys
# CHAINDOC_SECRET_KEY=sk_test_xxxxxxxxxxxxx
# Optional: Custom API endpoint
# CHAINDOC_API_URL=https://api.chaindoc.io3. samm: SDK algatamine
import { Chaindoc } from '@chaindoc_io/server-sdk';
// Basic initialization
export const chaindoc = new Chaindoc({
secretKey: process.env.CHAINDOC_SECRET_KEY!,
});
// Advanced configuration
export const chaindocAdvanced = new Chaindoc({
secretKey: process.env.CHAINDOC_SECRET_KEY!,
baseUrl: process.env.CHAINDOC_API_URL, // Optional
timeout: 60000, // 60 seconds
retry: {
maxRetries: 5,
baseDelayMs: 1000,
maxDelayMs: 10000,
},
headers: {
'X-Custom-Header': 'value',
},
});4. samm: ühenduse kontrollimine
// Test API connection
const health = await chaindoc.healthCheck();
if (health.status === 'ok' && health.apiKeyValid) {
console.log('✓ Connected to Chaindoc API');
console.log('User ID:', health.userId);
} else {
console.error('✗ Connection failed');
}SDK installimine
Embed SDK pakub veebirakenduste jaoks allkirjastamise liidest. Töötab mis tahes JavaScripti raamistikuga.
1. samm: Paigalda pakett
npm install @chaindoc_io/embed-sdk2. samm: konfigureerige keskkonnamuutujad
# .env.local
REACT_APP_CHAINDOC_PUBLIC_KEY=pk_live_xxxxx
# or for Next.js
NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY=pk_live_xxxxx3. samm: algatage oma rakenduses
// hooks/useChaindoc.ts
import { useRef, useEffect } from 'react';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
export function useChaindoc() {
const sdkRef = useRef<ChaindocEmbed | null>(null);
useEffect(() => {
sdkRef.current = new ChaindocEmbed({
publicKey: process.env.REACT_APP_CHAINDOC_PUBLIC_KEY!,
environment: 'production',
});
return () => {
sdkRef.current?.destroy();
};
}, []);
return sdkRef.current;
}Raamistikupõhine seadistus
Next.js (rakenduse ruuter)
'use client';
import { createContext, useContext, useEffect, useRef } from 'react';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
const ChaindocContext = createContext<ChaindocEmbed | null>(null);
export function ChaindocProvider({ children }: { children: React.ReactNode }) {
const sdkRef = useRef<ChaindocEmbed | null>(null);
useEffect(() => {
if (!sdkRef.current) {
sdkRef.current = new ChaindocEmbed({
publicKey: process.env.NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY!,
});
}
return () => {
sdkRef.current?.destroy();
};
}, []);
return (
<ChaindocContext.Provider value={sdkRef.current}>
{children}
</ChaindocContext.Provider>
);
}
export const useChaindoc = () => useContext(ChaindocContext);Next.js (Pages Router)
import type { AppProps } from 'next/app';
import { useEffect, useRef } from 'react';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
export default function App({ Component, pageProps }: AppProps) {
const sdkRef = useRef<ChaindocEmbed | null>(null);
useEffect(() => {
sdkRef.current = new ChaindocEmbed({
publicKey: process.env.NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY!,
});
return () => {
sdkRef.current?.destroy();
};
}, []);
return <Component {...pageProps} />;
}Nuxt 3
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig();
const chaindoc = new ChaindocEmbed({
publicKey: config.public.chaindocPublicKey,
});
return {
provide: {
chaindoc,
},
};
});Angular
import { Injectable, OnDestroy } from '@angular/core';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class ChaindocService implements OnDestroy {
private sdk: ChaindocEmbed;
constructor() {
this.sdk = new ChaindocEmbed({
publicKey: environment.chaindocPublicKey,
});
}
getSdk(): ChaindocEmbed {
return this.sdk;
}
ngOnDestroy(): void {
this.sdk.destroy();
}
}TypeScripti konfiguratsioon
Mõlemad SDK-d sisaldavad täielikke TypeScripti definitsioone. Täiendavaid @types pakette ei ole vaja.
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"types": ["node"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}Keskkonna konfiguratsioon
Arenduskeskkond
// Use test keys for development
const chaindoc = new Chaindoc({
secretKey: 'sk_test_xxxxx',
baseUrl: 'https://api.chaindoc.io',
});
const embed = new ChaindocEmbed({
publicKey: 'pk_test_xxxxx',
environment: 'staging',
debug: true, // Enable detailed logs
});Tootmiskeskkond
// Use live keys for production
const chaindoc = new Chaindoc({
secretKey: process.env.CHAINDOC_SECRET_KEY!, // sk_live_xxxxx
});
const embed = new ChaindocEmbed({
publicKey: process.env.NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY!, // pk_live_xxxxx
environment: 'production',
});Kinnitamine
Testige oma installatsiooni järgmiste kontrollimise sammude abil:
1Kontrollige SDK versiooniconsole.log(ChaindocEmbed.version); // Peaks väljastama versiooni numbri
2Kontrollige API-ühendustTestige tervisekontrolli lõpppunkti, et kinnitada API-võtmete kehtivust
3Testfaili üleslaadimineLaadige üles väike testfail, et kontrollida meedia lõpppunktide töötamist
4Initsialiseerige Embed SDKInitsialiseerige SDK ja kontrollige brauseri konsooli võimalike vigade suhtes
Vigade leidmine
Moodulit ei leitud
# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install
# For yarn
rm -rf node_modules yarn.lock
yarn installTypeScripti vead
Kui näed TypeScripti vigu, veendu, et su tsconfig.json-failis on õiged mooduli resolutsiooni seaded ja Node.js-tüübid on installitud.
npm install --save-dev @types/nodeAPI võtme probleemid
Järgmised sammud
- Vaadake läbi kiirjuhend oma esimese integratsiooni jaoks
- Kontrollige API dokumentatsiooni lõpppunkti viite jaoks
- Tutvuge SDK-dokumentatsiooniga, et saada teada täpsemalt täiustatud funktsioonidest.
- Seadista veebihookid reaalajas teavituste jaoks
- Liitu GitHubi arendajate kogukonnaga, et saada tuge