@nemme/js-sdk 0.2.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.
- package/README.md +8 -0
- package/dist/assets/js-sdk.css +1 -0
- package/dist/browser.d.ts +14 -0
- package/dist/client.d.ts +31 -0
- package/dist/config.d.ts +4 -0
- package/dist/deliveries/delivery-manager.d.ts +52 -0
- package/dist/forms/form-manager.d.ts +19 -0
- package/dist/forms/form-wrapper/form-wrapper.d.ts +13 -0
- package/dist/forms/form-wrapper/step.d.ts +13 -0
- package/dist/forms/form.d.ts +2 -0
- package/dist/forms/index.d.ts +5 -0
- package/dist/forms/question-choice/question-choice.d.ts +20 -0
- package/dist/forms/question-text/question-text.d.ts +15 -0
- package/dist/forms/question-wrapper.d.ts +14 -0
- package/dist/forms/transition-end/transition-end.d.ts +11 -0
- package/dist/forms/transition-start/transition-start.d.ts +12 -0
- package/dist/forms/transition-wrapper.d.ts +12 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/index.cjs +68 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +4904 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/nemme-sdk.umd.js +68 -0
- package/dist/nemme-sdk.umd.js.map +1 -0
- package/dist/networking/httpClient.d.ts +36 -0
- package/dist/networking/index.d.ts +2 -0
- package/dist/react/NemmeProvider.d.ts +9 -0
- package/dist/react/context.d.ts +7 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/useNemme.d.ts +8 -0
- package/dist/react/useNemmeContext.d.ts +1 -0
- package/dist/tracking/tracking-manager.d.ts +62 -0
- package/dist/translations/en.json.d.ts +9 -0
- package/dist/translations/nb.json.d.ts +4 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/logger.d.ts +26 -0
- package/package.json +88 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
2
|
+
export interface RequestOptions {
|
|
3
|
+
method?: HttpMethod;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
body?: unknown;
|
|
6
|
+
params?: Record<string, string | number | boolean>;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface HttpResponse<T = unknown> {
|
|
10
|
+
data: T;
|
|
11
|
+
status: number;
|
|
12
|
+
statusText: string;
|
|
13
|
+
headers: Headers;
|
|
14
|
+
ok: boolean;
|
|
15
|
+
error?: {
|
|
16
|
+
message: string;
|
|
17
|
+
details?: unknown;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Global HTTP client for making API requests
|
|
22
|
+
*/
|
|
23
|
+
export declare const httpClient: {
|
|
24
|
+
/**
|
|
25
|
+
* Make an HTTP request
|
|
26
|
+
*/
|
|
27
|
+
request<T = unknown>(endpoint: string, options?: RequestOptions): Promise<HttpResponse<T>>;
|
|
28
|
+
/**
|
|
29
|
+
* Convenience methods for common HTTP methods
|
|
30
|
+
*/
|
|
31
|
+
get<T = unknown>(endpoint: string, options?: Omit<RequestOptions, "method">): Promise<HttpResponse<T>>;
|
|
32
|
+
post<T = unknown>(endpoint: string, data?: unknown, options?: Omit<RequestOptions, "method" | "body">): Promise<HttpResponse<T>>;
|
|
33
|
+
put<T = unknown>(endpoint: string, data?: unknown, options?: Omit<RequestOptions, "method" | "body">): Promise<HttpResponse<T>>;
|
|
34
|
+
patch<T = unknown>(endpoint: string, data?: unknown, options?: Omit<RequestOptions, "method" | "body">): Promise<HttpResponse<T>>;
|
|
35
|
+
delete<T = unknown>(endpoint: string, options?: Omit<RequestOptions, "method">): Promise<HttpResponse<T>>;
|
|
36
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React, ReactNode } from 'react';
|
|
2
|
+
import { ClientConfigType } from '../client';
|
|
3
|
+
interface NemmeProviderProps {
|
|
4
|
+
clientKey: string;
|
|
5
|
+
config: ClientConfigType;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare const NemmeProvider: React.FC<NemmeProviderProps>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TrackEventOptions } from '../client';
|
|
2
|
+
export declare const useNemme: () => {
|
|
3
|
+
track: <T extends TrackEventOptions>(options: T) => Promise<void>;
|
|
4
|
+
flush: () => Promise<void>;
|
|
5
|
+
isInitialized: boolean;
|
|
6
|
+
error: string | null;
|
|
7
|
+
client: import('..').NemmeClient | null;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useNemmeContext: () => import('./context').NemmeContextType;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Logger } from '../utils';
|
|
2
|
+
export type Config = {
|
|
3
|
+
logger: Logger;
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
sessionId: number;
|
|
6
|
+
eventDefinitions: EventDefinition[];
|
|
7
|
+
batchConfig?: boolean | BatchConfig;
|
|
8
|
+
onPageView?: (url: string) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export type BatchConfig = {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
size?: number;
|
|
13
|
+
delayMs?: number;
|
|
14
|
+
sendOnUnload?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type TrackEventOptions<T extends string = string> = {
|
|
17
|
+
eventKey: T;
|
|
18
|
+
data?: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
type EventProperties = {
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
};
|
|
24
|
+
export type EventDefinition = {
|
|
25
|
+
properties: EventProperties[];
|
|
26
|
+
eventKey: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Manages event tracking, batching, and page view tracking
|
|
30
|
+
*/
|
|
31
|
+
export declare class TrackingManager {
|
|
32
|
+
private logger;
|
|
33
|
+
private headers;
|
|
34
|
+
private sessionId?;
|
|
35
|
+
private eventDefinitions;
|
|
36
|
+
private onPageView?;
|
|
37
|
+
private backlog;
|
|
38
|
+
private flushTimeout;
|
|
39
|
+
private batchConfig;
|
|
40
|
+
private originalHistoryMethods;
|
|
41
|
+
private readonly EVENT_PAGE_VIEW;
|
|
42
|
+
constructor({ logger, headers, sessionId, eventDefinitions, batchConfig, onPageView }: Config);
|
|
43
|
+
private setupBatching;
|
|
44
|
+
setupPageViewTracking(): Promise<void>;
|
|
45
|
+
track<T extends TrackEventOptions>(options: T): Promise<void>;
|
|
46
|
+
trackPageView(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Manually flush any pending events
|
|
49
|
+
*/
|
|
50
|
+
flush(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Clean up event listeners and restore original history methods
|
|
53
|
+
*/
|
|
54
|
+
destroy(): void;
|
|
55
|
+
private validateEvent;
|
|
56
|
+
private handlePopState;
|
|
57
|
+
private handleVisibilityChange;
|
|
58
|
+
private scheduleFlush;
|
|
59
|
+
private flushEvents;
|
|
60
|
+
private sendEvents;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility for the SDK
|
|
3
|
+
* Provides consistent logging across the SDK with different log levels
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
6
|
+
interface LoggerOptions {
|
|
7
|
+
prefix?: string;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
level?: LogLevel;
|
|
10
|
+
}
|
|
11
|
+
export declare class Logger {
|
|
12
|
+
private prefix;
|
|
13
|
+
private enabled;
|
|
14
|
+
private level;
|
|
15
|
+
constructor(options?: LoggerOptions);
|
|
16
|
+
private shouldLog;
|
|
17
|
+
private formatMessage;
|
|
18
|
+
debug(message: string, ...args: unknown[]): void;
|
|
19
|
+
info(message: string, ...args: unknown[]): void;
|
|
20
|
+
warn(message: string, ...args: unknown[]): void;
|
|
21
|
+
error(message: string, ...args: unknown[]): void;
|
|
22
|
+
child(prefix: string): Logger;
|
|
23
|
+
configure(options: LoggerOptions): void;
|
|
24
|
+
}
|
|
25
|
+
export declare const logger: Logger;
|
|
26
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nemme/js-sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"browser": "./dist/nemme-sdk.umd.js",
|
|
9
|
+
"unpkg": "./dist/nemme-sdk.umd.js",
|
|
10
|
+
"jsdelivr": "./dist/nemme-sdk.umd.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"/dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "vitest",
|
|
16
|
+
"test:ci": "vitest run",
|
|
17
|
+
"debug": "vitest --test-timeout=0 --no-file-parallelism",
|
|
18
|
+
"cov": "vitest run --coverage",
|
|
19
|
+
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
|
20
|
+
"format:check": "prettier --check --parser typescript '**/*.{ts,tsx}'",
|
|
21
|
+
"lint": "eslint . --ext .ts,.tsx --cache",
|
|
22
|
+
"lint:fix": "eslint . --ext .ts,.tsx --fix",
|
|
23
|
+
"type-check": "tsc --noEmit",
|
|
24
|
+
"prebuild": "cd ../ui-kit && npm run build",
|
|
25
|
+
"build": "npm run prebuild && tsc && vite build",
|
|
26
|
+
"build:dev": "npm run prebuild && tsc && vite build --mode development",
|
|
27
|
+
"build:test": "npm run prebuild && tsc && vite build --mode test",
|
|
28
|
+
"dev": "vite",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"sb": "storybook dev -p 6006 --no-open",
|
|
31
|
+
"build-storybook": "storybook build",
|
|
32
|
+
"comp": "node ../scripts/generate-component.js"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"sdk"
|
|
36
|
+
],
|
|
37
|
+
"author": "Nemme AS",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"description": "Nemme JS SDK",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@phosphor-icons/react": "^2.1.10",
|
|
42
|
+
"date-fns": "^4.1.0",
|
|
43
|
+
"i18next-browser-languagedetector": "^8.2.0",
|
|
44
|
+
"react": "^18.0.0",
|
|
45
|
+
"react-dom": "^18.0.0",
|
|
46
|
+
"react-i18next": "^15.5.3"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@nemme/ui-kit": "^0.2.0",
|
|
50
|
+
"@chromatic-com/storybook": "^4.0.1",
|
|
51
|
+
"@eslint/compat": "^1.2.9",
|
|
52
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
53
|
+
"@eslint/js": "^9.28.0",
|
|
54
|
+
"@storybook/addon-a11y": "^9.0.13",
|
|
55
|
+
"@storybook/addon-docs": "^9.0.13",
|
|
56
|
+
"@storybook/addon-vitest": "^9.0.13",
|
|
57
|
+
"@storybook/react-vite": "^9.0.13",
|
|
58
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
59
|
+
"@testing-library/react": "^16.3.0",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
|
61
|
+
"@typescript-eslint/parser": "^8.33.1",
|
|
62
|
+
"@vitejs/plugin-react": "^4.5.1",
|
|
63
|
+
"@vitest/browser": "^3.2.4",
|
|
64
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
65
|
+
"autoprefixer": "^10.4.20",
|
|
66
|
+
"eslint": "^9.28.0",
|
|
67
|
+
"eslint-config-prettier": "^10.1.5",
|
|
68
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
69
|
+
"eslint-plugin-react": "^7.37.5",
|
|
70
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
|
71
|
+
"eslint-plugin-storybook": "^9.0.13",
|
|
72
|
+
"globals": "^16.2.0",
|
|
73
|
+
"happy-dom": "^17.6.3",
|
|
74
|
+
"husky": "^9.1.7",
|
|
75
|
+
"lint-staged": "^16.1.0",
|
|
76
|
+
"playwright": "^1.53.1",
|
|
77
|
+
"postcss": "^8.5.6",
|
|
78
|
+
"postcss-import": "^16.1.1",
|
|
79
|
+
"postcss-prefixwrap": "^1.56.2",
|
|
80
|
+
"prettier": "^3.5.1",
|
|
81
|
+
"storybook": "^9.0.13",
|
|
82
|
+
"tailwindcss": "^3.4.17",
|
|
83
|
+
"typescript": "^5.8.3",
|
|
84
|
+
"vite": "^6.3.5",
|
|
85
|
+
"vite-plugin-dts": "^4.5.4",
|
|
86
|
+
"vitest": "^3.2.1"
|
|
87
|
+
}
|
|
88
|
+
}
|