@nibgate/sdk 0.1.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,23 @@
1
+ import type { NibgatePaymentInput, NibgateServerOptions, NibgateServerResource } from './server.js';
2
+
3
+ export declare function emitTestEvents(resource: NibgateServerResource | string, options?: NibgateServerOptions & {
4
+ siteId?: string;
5
+ token?: string;
6
+ apiBaseUrl?: string;
7
+ visitorId?: string;
8
+ sessionId?: string;
9
+ source?: string;
10
+ payload?: Record<string, unknown>;
11
+ payment?: NibgatePaymentInput;
12
+ paymentProvider?: string;
13
+ paymentId?: string;
14
+ rating?: number | false;
15
+ walletAddress?: string;
16
+ payer?: string;
17
+ ratingSignature?: string;
18
+ signature?: string;
19
+ reviewHash?: string;
20
+ txHash?: string;
21
+ proofType?: string;
22
+ proof?: string;
23
+ }): Promise<Record<string, unknown>>;
package/src/testing.js ADDED
@@ -0,0 +1,56 @@
1
+ import { emitHubEvent, normalizeResource } from './server.js';
2
+
3
+ export async function emitTestEvents(resourceInput, options = {}) {
4
+ const resource = normalizeResource(resourceInput);
5
+ const payment = {
6
+ paymentProvider: options.paymentProvider || 'nibgate-package-test',
7
+ paymentId: options.paymentId || `nibgate_test_${Date.now()}`,
8
+ amount: Number(resource.price || 0),
9
+ revenue: Number(resource.price || 0),
10
+ currency: resource.currency || 'USDC',
11
+ ...(options.payment || {})
12
+ };
13
+ const shared = {
14
+ ...options,
15
+ payload: {
16
+ source: options.source || 'nibgate-package-test',
17
+ ...(options.payload || {})
18
+ }
19
+ };
20
+
21
+ const events = [];
22
+ events.push(await emitHubEvent('content_registered', resource, shared));
23
+ events.push(await emitHubEvent('resource_view', resource, shared));
24
+ events.push(await emitHubEvent('unlock_started', resource, {
25
+ ...shared,
26
+ payload: { ...(shared.payload || {}), paymentProvider: payment.paymentProvider }
27
+ }));
28
+ events.push(await emitHubEvent('payment_completed', resource, {
29
+ ...shared,
30
+ payload: { ...(shared.payload || {}), ...payment }
31
+ }));
32
+ events.push(await emitHubEvent('unlock_completed', resource, {
33
+ ...shared,
34
+ payload: { ...(shared.payload || {}), ...payment }
35
+ }));
36
+
37
+ if (options.rating && (options.ratingSignature || options.signature || options.txHash)) {
38
+ events.push(await emitHubEvent('content_rating', resource, {
39
+ ...shared,
40
+ payload: {
41
+ ...(shared.payload || {}),
42
+ ...payment,
43
+ walletAddress: options.walletAddress || options.payer || payment.payer || '',
44
+ rating: options.rating || 4.5,
45
+ ratingMessage: options.ratingMessage || '',
46
+ ratingSignature: options.ratingSignature || options.signature || '',
47
+ reviewHash: options.reviewHash || '',
48
+ txHash: options.txHash || '',
49
+ proofType: options.proofType || (options.txHash ? 'onchain_pending' : 'signed'),
50
+ proof: options.proof || payment.paymentId
51
+ }
52
+ }));
53
+ }
54
+
55
+ return { success: true, events, payment };
56
+ }
@@ -0,0 +1,18 @@
1
+ import type { NibgatePageOptions, NibgateResource } from './index.js';
2
+
3
+ export interface NibgateTrackingGate {
4
+ resource: NibgateResource;
5
+ content(extra?: Record<string, unknown>): void;
6
+ view(extra?: Record<string, unknown>): void;
7
+ track(eventName: string, payload?: Record<string, unknown>): void;
8
+ }
9
+
10
+ export declare function createTrackingGate(resource: NibgateResource | string): NibgateTrackingGate;
11
+ export declare function trackResourcePage(resource: NibgateResource | string, options?: NibgatePageOptions): NibgateTrackingGate;
12
+ export declare function normalizeResource(resource?: NibgateResource | string): NibgateResource;
13
+ export declare function validateResourceMetadata(resource?: NibgateResource | string, options?: Record<string, unknown>): {
14
+ ok: boolean;
15
+ score: number;
16
+ warnings: string[];
17
+ errors: string[];
18
+ };
@@ -0,0 +1 @@
1
+ export * from './browser/tracking.js';