@ned-ai/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.
- package/README.md +94 -0
- package/dist/client.d.ts +60 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +100 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +57 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/analytics.d.ts +212 -0
- package/dist/resources/analytics.d.ts.map +1 -0
- package/dist/resources/analytics.js +93 -0
- package/dist/resources/analytics.js.map +1 -0
- package/dist/resources/customers.d.ts +110 -0
- package/dist/resources/customers.d.ts.map +1 -0
- package/dist/resources/customers.js +53 -0
- package/dist/resources/customers.js.map +1 -0
- package/dist/resources/marketing.d.ts +109 -0
- package/dist/resources/marketing.d.ts.map +1 -0
- package/dist/resources/marketing.js +45 -0
- package/dist/resources/marketing.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @ned-ai/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [Ned AI](https://meetned.com) API. Access your Shopify store analytics, profitability, customer segments, and marketing metrics programmatically.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ned-ai/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { NedClient } from '@ned-ai/sdk';
|
|
15
|
+
|
|
16
|
+
const ned = new NedClient({ apiKey: process.env.NED_API_KEY! });
|
|
17
|
+
|
|
18
|
+
// Get today's sales
|
|
19
|
+
const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
20
|
+
console.log(sales.data.metrics.revenue);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API Reference
|
|
24
|
+
|
|
25
|
+
### Analytics
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
// Sales analytics with period comparison
|
|
29
|
+
ned.analytics.getSalesContext({ period: 'this_month', comparison: 'year_ago' })
|
|
30
|
+
|
|
31
|
+
// Daily sales breakdown
|
|
32
|
+
ned.analytics.getDailySales({ period: 'last_30_days' })
|
|
33
|
+
|
|
34
|
+
// Revenue forecast (Growth+ tier)
|
|
35
|
+
ned.analytics.getForecast(30)
|
|
36
|
+
|
|
37
|
+
// Profitability summary
|
|
38
|
+
ned.analytics.getProfitability({ period: 'this_month', view_type: 'summary' })
|
|
39
|
+
|
|
40
|
+
// Product-level profitability
|
|
41
|
+
ned.analytics.getProductProfitability({ sort_by: 'profit', limit: 10 })
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Customers
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Customer overview
|
|
48
|
+
ned.customers.getSummary()
|
|
49
|
+
|
|
50
|
+
// Customer segments by profit or activity tier
|
|
51
|
+
ned.customers.getSegments({ segment: 'profit_tier', limit: 10 })
|
|
52
|
+
|
|
53
|
+
// At-risk high-value customers
|
|
54
|
+
ned.customers.getAtRisk({ limit: 20 })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Marketing
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Marketing efficiency (MER, CAC, ROAS)
|
|
61
|
+
ned.marketing.getMetrics({ period: 'this_month', view_type: 'summary' })
|
|
62
|
+
|
|
63
|
+
// Ad performance across platforms
|
|
64
|
+
ned.marketing.getAds({ period: 'last_30_days', platform: 'meta' })
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Period Options
|
|
68
|
+
|
|
69
|
+
`today` | `yesterday` | `this_week` | `last_week` | `this_month` | `last_month` | `last_7_days` | `last_30_days` | `mtd` | `ytd`
|
|
70
|
+
|
|
71
|
+
## Error Handling
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { NedApiError, NedRateLimitError } from '@ned-ai/sdk';
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const sales = await ned.analytics.getSalesContext();
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err instanceof NedRateLimitError) {
|
|
80
|
+
console.log(`Rate limited. Retry after ${err.retryAfter}s`);
|
|
81
|
+
} else if (err instanceof NedApiError) {
|
|
82
|
+
console.log(`API error ${err.statusCode}: ${err.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Requirements
|
|
88
|
+
|
|
89
|
+
- Node.js 18+
|
|
90
|
+
- A Ned API key (get one at [meetned.com](https://meetned.com))
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NedClient - Main SDK client for the Ned AI API
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { NedClient } from '@ned-ai/sdk';
|
|
6
|
+
*
|
|
7
|
+
* const ned = new NedClient({ apiKey: process.env.NED_API_KEY });
|
|
8
|
+
* const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
9
|
+
*/
|
|
10
|
+
import { AnalyticsResource } from './resources/analytics.js';
|
|
11
|
+
import { CustomersResource } from './resources/customers.js';
|
|
12
|
+
import { MarketingResource } from './resources/marketing.js';
|
|
13
|
+
export interface NedClientOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Your Ned API key (starts with ned_live_)
|
|
16
|
+
*/
|
|
17
|
+
apiKey: string;
|
|
18
|
+
/**
|
|
19
|
+
* Base URL for the Ned API
|
|
20
|
+
* @default 'https://api.meetned.com'
|
|
21
|
+
*/
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Request timeout in milliseconds
|
|
25
|
+
* @default 30000
|
|
26
|
+
*/
|
|
27
|
+
timeout?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface RequestOptions {
|
|
30
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
31
|
+
body?: unknown;
|
|
32
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* NedClient - TypeScript SDK for the Ned AI API
|
|
36
|
+
*/
|
|
37
|
+
export declare class NedClient {
|
|
38
|
+
private readonly apiKey;
|
|
39
|
+
private readonly baseUrl;
|
|
40
|
+
private readonly timeout;
|
|
41
|
+
constructor(options: NedClientOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Make an authenticated request to the Ned API
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
request<T>(endpoint: string, options?: RequestOptions): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Analytics resource for sales, profitability, and forecast data
|
|
49
|
+
*/
|
|
50
|
+
get analytics(): AnalyticsResource;
|
|
51
|
+
/**
|
|
52
|
+
* Customers resource for segments, summaries, and at-risk analysis
|
|
53
|
+
*/
|
|
54
|
+
get customers(): CustomersResource;
|
|
55
|
+
/**
|
|
56
|
+
* Marketing resource for marketing metrics and ad performance
|
|
57
|
+
*/
|
|
58
|
+
get marketing(): MarketingResource;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC3C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CAChE;AAED;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,gBAAgB;IAcrC;;;OAGG;IACG,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IA0D5E;;OAEG;IACH,IAAI,SAAS,IAAI,iBAAiB,CAEjC;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,iBAAiB,CAEjC;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,iBAAiB,CAEjC;CACF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NedClient - Main SDK client for the Ned AI API
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { NedClient } from '@ned-ai/sdk';
|
|
6
|
+
*
|
|
7
|
+
* const ned = new NedClient({ apiKey: process.env.NED_API_KEY });
|
|
8
|
+
* const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
9
|
+
*/
|
|
10
|
+
import { AnalyticsResource } from './resources/analytics.js';
|
|
11
|
+
import { CustomersResource } from './resources/customers.js';
|
|
12
|
+
import { MarketingResource } from './resources/marketing.js';
|
|
13
|
+
import { NedApiError } from './errors.js';
|
|
14
|
+
/**
|
|
15
|
+
* NedClient - TypeScript SDK for the Ned AI API
|
|
16
|
+
*/
|
|
17
|
+
export class NedClient {
|
|
18
|
+
apiKey;
|
|
19
|
+
baseUrl;
|
|
20
|
+
timeout;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
if (!options.apiKey) {
|
|
23
|
+
throw new Error('API key is required');
|
|
24
|
+
}
|
|
25
|
+
if (!options.apiKey.startsWith('ned_live_')) {
|
|
26
|
+
throw new Error('Invalid API key format. Keys should start with ned_live_');
|
|
27
|
+
}
|
|
28
|
+
this.apiKey = options.apiKey;
|
|
29
|
+
this.baseUrl = options.baseUrl || 'https://api.meetned.com';
|
|
30
|
+
this.timeout = options.timeout || 30000;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Make an authenticated request to the Ned API
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
async request(endpoint, options = {}) {
|
|
37
|
+
const { method = 'GET', body, params } = options;
|
|
38
|
+
// Build URL with query params
|
|
39
|
+
const url = new URL(`${this.baseUrl}/api/v1${endpoint}`);
|
|
40
|
+
if (params) {
|
|
41
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
42
|
+
if (value !== undefined) {
|
|
43
|
+
url.searchParams.set(key, String(value));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Create abort controller for timeout
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(url.toString(), {
|
|
52
|
+
method,
|
|
53
|
+
headers: {
|
|
54
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
},
|
|
57
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
58
|
+
signal: controller.signal,
|
|
59
|
+
});
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
63
|
+
throw new NedApiError(errorBody.message || `API error: ${response.status}`, response.status, errorBody.error);
|
|
64
|
+
}
|
|
65
|
+
return await response.json();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
clearTimeout(timeoutId);
|
|
69
|
+
if (error instanceof NedApiError) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
if (error instanceof Error) {
|
|
73
|
+
if (error.name === 'AbortError') {
|
|
74
|
+
throw new Error(`Request timeout after ${this.timeout}ms`);
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
throw new Error('Unknown error occurred');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Analytics resource for sales, profitability, and forecast data
|
|
83
|
+
*/
|
|
84
|
+
get analytics() {
|
|
85
|
+
return new AnalyticsResource(this);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Customers resource for segments, summaries, and at-risk analysis
|
|
89
|
+
*/
|
|
90
|
+
get customers() {
|
|
91
|
+
return new CustomersResource(this);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Marketing resource for marketing metrics and ad performance
|
|
95
|
+
*/
|
|
96
|
+
get marketing() {
|
|
97
|
+
return new MarketingResource(this);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,W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C,CAAC;gBAC7D,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the Ned SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for Ned API errors
|
|
6
|
+
*/
|
|
7
|
+
export declare class NedApiError extends Error {
|
|
8
|
+
readonly statusCode: number;
|
|
9
|
+
readonly errorCode?: string;
|
|
10
|
+
constructor(message: string, statusCode: number, errorCode?: string);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Error class for rate limit errors (429)
|
|
14
|
+
*/
|
|
15
|
+
export declare class NedRateLimitError extends NedApiError {
|
|
16
|
+
readonly retryAfter?: number;
|
|
17
|
+
constructor(message: string, retryAfter?: number);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error class for authentication errors (401)
|
|
21
|
+
*/
|
|
22
|
+
export declare class NedAuthError extends NedApiError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error class for forbidden access (403)
|
|
27
|
+
*/
|
|
28
|
+
export declare class NedForbiddenError extends NedApiError {
|
|
29
|
+
constructor(message?: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Error class for validation errors (400)
|
|
33
|
+
*/
|
|
34
|
+
export declare class NedValidationError extends NedApiError {
|
|
35
|
+
readonly parameter?: string;
|
|
36
|
+
constructor(message: string, parameter?: string);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAMpE;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAKjD;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,WAAW;gBAC/B,OAAO,GAAE,MAAqC;CAI3D;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,OAAO,GAAE,MAAgE;CAItF;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAKhD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the Ned SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for Ned API errors
|
|
6
|
+
*/
|
|
7
|
+
export class NedApiError extends Error {
|
|
8
|
+
statusCode;
|
|
9
|
+
errorCode;
|
|
10
|
+
constructor(message, statusCode, errorCode) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'NedApiError';
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.errorCode = errorCode;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Error class for rate limit errors (429)
|
|
19
|
+
*/
|
|
20
|
+
export class NedRateLimitError extends NedApiError {
|
|
21
|
+
retryAfter;
|
|
22
|
+
constructor(message, retryAfter) {
|
|
23
|
+
super(message, 429, 'rate_limit_exceeded');
|
|
24
|
+
this.name = 'NedRateLimitError';
|
|
25
|
+
this.retryAfter = retryAfter;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Error class for authentication errors (401)
|
|
30
|
+
*/
|
|
31
|
+
export class NedAuthError extends NedApiError {
|
|
32
|
+
constructor(message = 'Invalid or expired API key') {
|
|
33
|
+
super(message, 401, 'unauthorized');
|
|
34
|
+
this.name = 'NedAuthError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error class for forbidden access (403)
|
|
39
|
+
*/
|
|
40
|
+
export class NedForbiddenError extends NedApiError {
|
|
41
|
+
constructor(message = 'Access denied - upgrade your plan to use this feature') {
|
|
42
|
+
super(message, 403, 'forbidden');
|
|
43
|
+
this.name = 'NedForbiddenError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Error class for validation errors (400)
|
|
48
|
+
*/
|
|
49
|
+
export class NedValidationError extends NedApiError {
|
|
50
|
+
parameter;
|
|
51
|
+
constructor(message, parameter) {
|
|
52
|
+
super(message, 400, 'invalid_parameter');
|
|
53
|
+
this.name = 'NedValidationError';
|
|
54
|
+
this.parameter = parameter;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG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C;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ned-ai/sdk - TypeScript SDK for the Ned AI API
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { NedClient } from '@ned-ai/sdk';
|
|
6
|
+
*
|
|
7
|
+
* const ned = new NedClient({ apiKey: process.env.NED_API_KEY });
|
|
8
|
+
* const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
9
|
+
*/
|
|
10
|
+
export { NedClient } from './client.js';
|
|
11
|
+
export type { NedClientOptions, RequestOptions } from './client.js';
|
|
12
|
+
export { AnalyticsResource } from './resources/analytics.js';
|
|
13
|
+
export type { Period, Comparison, GetSalesContextParams, GetDailySalesParams, GetProfitabilityParams, GetProductProfitabilityParams, SalesContextResponse, DailySalesResponse, ForecastResponse, ProfitabilityResponse, ProductProfitabilityResponse, } from './resources/analytics.js';
|
|
14
|
+
export { CustomersResource } from './resources/customers.js';
|
|
15
|
+
export type { GetCustomerSegmentsParams, GetAtRiskParams, CustomerSummaryResponse, CustomerSegmentsResponse, AtRiskCustomersResponse, } from './resources/customers.js';
|
|
16
|
+
export { MarketingResource } from './resources/marketing.js';
|
|
17
|
+
export type { GetMarketingMetricsParams, GetAdsParams, MarketingMetricsResponse, AdsPerformanceResponse, } from './resources/marketing.js';
|
|
18
|
+
export { NedApiError, NedRateLimitError, NedAuthError, NedForbiddenError, NedValidationError, } from './errors.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EACV,MAAM,EACN,UAAU,EACV,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,6BAA6B,EAC7B,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EACV,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EACV,yBAAyB,EACzB,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ned-ai/sdk - TypeScript SDK for the Ned AI API
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { NedClient } from '@ned-ai/sdk';
|
|
6
|
+
*
|
|
7
|
+
* const ned = new NedClient({ apiKey: process.env.NED_API_KEY });
|
|
8
|
+
* const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
9
|
+
*/
|
|
10
|
+
export { NedClient } from './client.js';
|
|
11
|
+
// Resource classes and types
|
|
12
|
+
export { AnalyticsResource } from './resources/analytics.js';
|
|
13
|
+
export { CustomersResource } from './resources/customers.js';
|
|
14
|
+
export { MarketingResource } from './resources/marketing.js';
|
|
15
|
+
// Error classes
|
|
16
|
+
export { NedApiError, NedRateLimitError, NedAuthError, NedForbiddenError, NedValidationError, } from './errors.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,6BAA6B;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAe7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAS7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAQ7D,gBAAgB;AAChB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Resource - Sales, Profitability, and Forecast endpoints
|
|
3
|
+
*/
|
|
4
|
+
import type { NedClient } from '../client.js';
|
|
5
|
+
/**
|
|
6
|
+
* Period options for analytics queries
|
|
7
|
+
*/
|
|
8
|
+
export type Period = 'today' | 'yesterday' | 'this_week' | 'last_week' | 'this_month' | 'last_month' | 'last_7_days' | 'last_30_days' | 'mtd' | 'ytd';
|
|
9
|
+
/**
|
|
10
|
+
* Comparison options
|
|
11
|
+
*/
|
|
12
|
+
export type Comparison = 'year_ago' | 'prior_period';
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for getSalesContext
|
|
15
|
+
*/
|
|
16
|
+
export interface GetSalesContextParams {
|
|
17
|
+
period?: Period;
|
|
18
|
+
comparison?: Comparison;
|
|
19
|
+
timezone?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parameters for getProfitability
|
|
23
|
+
*/
|
|
24
|
+
export interface GetProfitabilityParams {
|
|
25
|
+
period?: Period;
|
|
26
|
+
view_type?: 'summary' | 'daily';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parameters for getProductProfitability
|
|
30
|
+
*/
|
|
31
|
+
export interface GetProductProfitabilityParams {
|
|
32
|
+
period?: Period;
|
|
33
|
+
sort_by?: 'revenue' | 'profit' | 'margin' | 'units';
|
|
34
|
+
limit?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sales analytics response
|
|
38
|
+
*/
|
|
39
|
+
export interface SalesContextResponse {
|
|
40
|
+
data: {
|
|
41
|
+
period: string;
|
|
42
|
+
metrics: {
|
|
43
|
+
revenue: number;
|
|
44
|
+
orders: number;
|
|
45
|
+
aov: number;
|
|
46
|
+
new_customers: number;
|
|
47
|
+
returning_customers: number;
|
|
48
|
+
unique_customers: number;
|
|
49
|
+
};
|
|
50
|
+
profitability: Record<string, unknown> | null;
|
|
51
|
+
customer_economics: Record<string, unknown> | null;
|
|
52
|
+
marketing: Record<string, unknown> | null;
|
|
53
|
+
comparisons: Record<string, unknown>;
|
|
54
|
+
insights: unknown[];
|
|
55
|
+
};
|
|
56
|
+
metadata: {
|
|
57
|
+
source: string;
|
|
58
|
+
period: string;
|
|
59
|
+
timezone: string;
|
|
60
|
+
comparison: string;
|
|
61
|
+
data_freshness: string;
|
|
62
|
+
requested_at: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Forecast response
|
|
67
|
+
*/
|
|
68
|
+
export interface ForecastResponse {
|
|
69
|
+
data: {
|
|
70
|
+
forecasts: unknown[];
|
|
71
|
+
summary: Record<string, unknown>;
|
|
72
|
+
};
|
|
73
|
+
metadata: {
|
|
74
|
+
method: string;
|
|
75
|
+
historical_days: number;
|
|
76
|
+
trend_direction: string;
|
|
77
|
+
confidence_level: number;
|
|
78
|
+
timezone: string;
|
|
79
|
+
requested_at: string;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Profitability response
|
|
84
|
+
*/
|
|
85
|
+
export interface ProfitabilityResponse {
|
|
86
|
+
data: {
|
|
87
|
+
view_type: string;
|
|
88
|
+
date_range: Record<string, unknown>;
|
|
89
|
+
days_analyzed: number;
|
|
90
|
+
summary: Record<string, unknown> | null;
|
|
91
|
+
daily_data: unknown[] | null;
|
|
92
|
+
cogs_coverage: Record<string, unknown> | null;
|
|
93
|
+
};
|
|
94
|
+
metadata: {
|
|
95
|
+
source: string;
|
|
96
|
+
period: string;
|
|
97
|
+
view_type: string;
|
|
98
|
+
requested_at: string;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Product profitability response
|
|
103
|
+
*/
|
|
104
|
+
export interface ProductProfitabilityResponse {
|
|
105
|
+
data: {
|
|
106
|
+
date_range: Record<string, unknown>;
|
|
107
|
+
products_count: number;
|
|
108
|
+
products: unknown[];
|
|
109
|
+
};
|
|
110
|
+
metadata: {
|
|
111
|
+
source: string;
|
|
112
|
+
period: string;
|
|
113
|
+
sort_by: string;
|
|
114
|
+
limit: number;
|
|
115
|
+
requested_at: string;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parameters for getDailySales
|
|
120
|
+
*/
|
|
121
|
+
export interface GetDailySalesParams {
|
|
122
|
+
period?: Period;
|
|
123
|
+
timezone?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Daily sales response
|
|
127
|
+
*/
|
|
128
|
+
export interface DailySalesResponse {
|
|
129
|
+
data: {
|
|
130
|
+
period: {
|
|
131
|
+
start_date: string;
|
|
132
|
+
end_date: string;
|
|
133
|
+
days_count: number;
|
|
134
|
+
};
|
|
135
|
+
days: Array<{
|
|
136
|
+
date: string;
|
|
137
|
+
revenue: number;
|
|
138
|
+
orders: number;
|
|
139
|
+
aov: number;
|
|
140
|
+
new_customers: number;
|
|
141
|
+
returning_customers: number;
|
|
142
|
+
net_profit: number;
|
|
143
|
+
margin_pct: number;
|
|
144
|
+
}>;
|
|
145
|
+
totals: {
|
|
146
|
+
revenue: number;
|
|
147
|
+
orders: number;
|
|
148
|
+
new_customers: number;
|
|
149
|
+
returning_customers: number;
|
|
150
|
+
net_profit: number;
|
|
151
|
+
aov: number;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
metadata: {
|
|
155
|
+
source: string;
|
|
156
|
+
period: string;
|
|
157
|
+
timezone: string;
|
|
158
|
+
requested_at: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Analytics resource for sales, profitability, and forecast data
|
|
163
|
+
*/
|
|
164
|
+
export declare class AnalyticsResource {
|
|
165
|
+
private client;
|
|
166
|
+
constructor(client: NedClient);
|
|
167
|
+
/**
|
|
168
|
+
* Get sales context/analytics
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
172
|
+
* console.log(sales.data.metrics.revenue);
|
|
173
|
+
*/
|
|
174
|
+
getSalesContext(params?: GetSalesContextParams): Promise<SalesContextResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Get daily sales breakdown
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* const daily = await ned.analytics.getDailySales({ period: 'last_30_days' });
|
|
180
|
+
* console.log(daily.data.days);
|
|
181
|
+
*/
|
|
182
|
+
getDailySales(params?: GetDailySalesParams): Promise<DailySalesResponse>;
|
|
183
|
+
/**
|
|
184
|
+
* Get revenue forecast (Growth+ tier required)
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const forecast = await ned.analytics.getForecast(30);
|
|
188
|
+
* console.log(forecast.data.forecasts[0].predicted_revenue);
|
|
189
|
+
*/
|
|
190
|
+
getForecast(days?: number): Promise<ForecastResponse>;
|
|
191
|
+
/**
|
|
192
|
+
* Get profitability metrics
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* const profit = await ned.analytics.getProfitability({ period: 'this_month' });
|
|
196
|
+
* console.log(profit.data.metrics.gross_margin);
|
|
197
|
+
*/
|
|
198
|
+
getProfitability(params?: GetProfitabilityParams): Promise<ProfitabilityResponse>;
|
|
199
|
+
/**
|
|
200
|
+
* Get product-level profitability
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* const products = await ned.analytics.getProductProfitability({
|
|
204
|
+
* period: 'last_30_days',
|
|
205
|
+
* sort_by: 'profit',
|
|
206
|
+
* limit: 10
|
|
207
|
+
* });
|
|
208
|
+
* console.log(products.data.products);
|
|
209
|
+
*/
|
|
210
|
+
getProductProfitability(params?: GetProductProfitabilityParams): Promise<ProductProfitabilityResponse>;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/resources/analytics.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,MAAM,GACd,OAAO,GACP,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,cAAc,GACd,KAAK,GACL,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,cAAc,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,o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+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Analytics resource for sales, profitability, and forecast data
|
|
6
|
+
*/
|
|
7
|
+
export class AnalyticsResource {
|
|
8
|
+
client;
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get sales context/analytics
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const sales = await ned.analytics.getSalesContext({ period: 'today' });
|
|
17
|
+
* console.log(sales.data.metrics.revenue);
|
|
18
|
+
*/
|
|
19
|
+
async getSalesContext(params = {}) {
|
|
20
|
+
return this.client.request('/sales/analytics', {
|
|
21
|
+
params: {
|
|
22
|
+
period: params.period,
|
|
23
|
+
comparison: params.comparison,
|
|
24
|
+
timezone: params.timezone,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get daily sales breakdown
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const daily = await ned.analytics.getDailySales({ period: 'last_30_days' });
|
|
33
|
+
* console.log(daily.data.days);
|
|
34
|
+
*/
|
|
35
|
+
async getDailySales(params = {}) {
|
|
36
|
+
return this.client.request('/sales/daily', {
|
|
37
|
+
params: {
|
|
38
|
+
period: params.period,
|
|
39
|
+
timezone: params.timezone,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get revenue forecast (Growth+ tier required)
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const forecast = await ned.analytics.getForecast(30);
|
|
48
|
+
* console.log(forecast.data.forecasts[0].predicted_revenue);
|
|
49
|
+
*/
|
|
50
|
+
async getForecast(days = 30) {
|
|
51
|
+
return this.client.request('/sales/forecast', {
|
|
52
|
+
params: {
|
|
53
|
+
days,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get profitability metrics
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* const profit = await ned.analytics.getProfitability({ period: 'this_month' });
|
|
62
|
+
* console.log(profit.data.metrics.gross_margin);
|
|
63
|
+
*/
|
|
64
|
+
async getProfitability(params = {}) {
|
|
65
|
+
return this.client.request('/profitability/summary', {
|
|
66
|
+
params: {
|
|
67
|
+
period: params.period,
|
|
68
|
+
view_type: params.view_type,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get product-level profitability
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const products = await ned.analytics.getProductProfitability({
|
|
77
|
+
* period: 'last_30_days',
|
|
78
|
+
* sort_by: 'profit',
|
|
79
|
+
* limit: 10
|
|
80
|
+
* });
|
|
81
|
+
* console.log(products.data.products);
|
|
82
|
+
*/
|
|
83
|
+
async getProductProfitability(params = {}) {
|
|
84
|
+
return this.client.request('/profitability/products', {
|
|
85
|
+
params: {
|
|
86
|
+
period: params.period,
|
|
87
|
+
sort_by: params.sort_by,
|
|
88
|
+
limit: params.limit,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/resources/analytics.ts"],"names":[],"mappings":"AAAA;;GAEG;AAqLH;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAEzC;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,SAAgC,EAAE;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAuB,kBAAkB,EAAE;YACnE,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,aAAa,CAAC,SAA8B,EAAE;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAqB,cAAc,EAAE;YAC7D,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAmB,iBAAiB,EAAE;YAC9D,MAAM,EAAE;gBACN,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,gBAAgB,CAAC,SAAiC,EAAE;QACxD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAwB,wBAAwB,EAAE;YAC1E,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,uBAAuB,CAAC,SAAwC,EAAE;QACtE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA+B,yBAAyB,EAAE;YAClF,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customers Resource - Customer segments, summaries, and at-risk analysis
|
|
3
|
+
*/
|
|
4
|
+
import type { NedClient } from '../client.js';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for getSegments
|
|
7
|
+
*/
|
|
8
|
+
export interface GetCustomerSegmentsParams {
|
|
9
|
+
segment?: 'profit_tier' | 'activity_tier' | 'both';
|
|
10
|
+
limit?: number;
|
|
11
|
+
min_orders?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for getAtRisk
|
|
15
|
+
*/
|
|
16
|
+
export interface GetAtRiskParams {
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Customer summary response
|
|
21
|
+
*/
|
|
22
|
+
export interface CustomerSummaryResponse {
|
|
23
|
+
data: {
|
|
24
|
+
total_customers: number;
|
|
25
|
+
avg_customer_profit: number;
|
|
26
|
+
avg_customer_ltv: number;
|
|
27
|
+
profitable_customer_pct: number;
|
|
28
|
+
by_profit_tier: {
|
|
29
|
+
whale: number;
|
|
30
|
+
profitable: number;
|
|
31
|
+
marginal: number;
|
|
32
|
+
unprofitable: number;
|
|
33
|
+
};
|
|
34
|
+
by_activity_tier: {
|
|
35
|
+
active: number;
|
|
36
|
+
cooling: number;
|
|
37
|
+
at_risk: number;
|
|
38
|
+
churned: number;
|
|
39
|
+
};
|
|
40
|
+
top_profitable_customers: unknown[];
|
|
41
|
+
at_risk_whales: unknown[];
|
|
42
|
+
};
|
|
43
|
+
metadata: {
|
|
44
|
+
source: string;
|
|
45
|
+
requested_at: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Customer segments response
|
|
50
|
+
*/
|
|
51
|
+
export interface CustomerSegmentsResponse {
|
|
52
|
+
data: {
|
|
53
|
+
by_profit_tier?: Record<string, unknown[]>;
|
|
54
|
+
by_activity_tier?: Record<string, unknown[]>;
|
|
55
|
+
};
|
|
56
|
+
metadata: {
|
|
57
|
+
source: string;
|
|
58
|
+
segment: string;
|
|
59
|
+
limit: number;
|
|
60
|
+
min_orders: number;
|
|
61
|
+
requested_at: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* At-risk customers response
|
|
66
|
+
*/
|
|
67
|
+
export interface AtRiskCustomersResponse {
|
|
68
|
+
data: {
|
|
69
|
+
customers: unknown[];
|
|
70
|
+
total_profit_at_risk: number;
|
|
71
|
+
customers_count: number;
|
|
72
|
+
};
|
|
73
|
+
metadata: {
|
|
74
|
+
source: string;
|
|
75
|
+
limit: number;
|
|
76
|
+
requested_at: string;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Customers resource for customer analytics and segmentation
|
|
81
|
+
*/
|
|
82
|
+
export declare class CustomersResource {
|
|
83
|
+
private client;
|
|
84
|
+
constructor(client: NedClient);
|
|
85
|
+
/**
|
|
86
|
+
* Get customer summary overview
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const summary = await ned.customers.getSummary();
|
|
90
|
+
* console.log(summary.data.total_customers);
|
|
91
|
+
*/
|
|
92
|
+
getSummary(): Promise<CustomerSummaryResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Get customer segments breakdown
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const segments = await ned.customers.getSegments({ segment: 'profit_tier', limit: 10 });
|
|
98
|
+
* console.log(segments.data.by_profit_tier);
|
|
99
|
+
*/
|
|
100
|
+
getSegments(params?: GetCustomerSegmentsParams): Promise<CustomerSegmentsResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Get at-risk customers (high-value customers showing churn signals)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const atRisk = await ned.customers.getAtRisk({ limit: 20 });
|
|
106
|
+
* console.log(atRisk.data.total_profit_at_risk);
|
|
107
|
+
*/
|
|
108
|
+
getAtRisk(params?: GetAtRiskParams): Promise<AtRiskCustomersResponse>;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=customers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.d.ts","sourceRoot":"","sources":["../../src/resources/customers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,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE;QACJ,SAAS,EAAE,OAAO,EAAE,CAAC;QACrB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAErC;;;;;;OAMG;IACG,UAAU,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAIpD;;;;;;OAMG;IACG,WAAW,CAAC,MAAM,GAAE,yBAA8B,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAU5F;;;;;;OAMG;IACG,SAAS,CAAC,MAAM,GAAE,eAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAOhF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customers Resource - Customer segments, summaries, and at-risk analysis
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Customers resource for customer analytics and segmentation
|
|
6
|
+
*/
|
|
7
|
+
export class CustomersResource {
|
|
8
|
+
client;
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get customer summary overview
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const summary = await ned.customers.getSummary();
|
|
17
|
+
* console.log(summary.data.total_customers);
|
|
18
|
+
*/
|
|
19
|
+
async getSummary() {
|
|
20
|
+
return this.client.request('/customers/summary');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get customer segments breakdown
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const segments = await ned.customers.getSegments({ segment: 'profit_tier', limit: 10 });
|
|
27
|
+
* console.log(segments.data.by_profit_tier);
|
|
28
|
+
*/
|
|
29
|
+
async getSegments(params = {}) {
|
|
30
|
+
return this.client.request('/customers/segments', {
|
|
31
|
+
params: {
|
|
32
|
+
segment: params.segment,
|
|
33
|
+
limit: params.limit,
|
|
34
|
+
min_orders: params.min_orders,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get at-risk customers (high-value customers showing churn signals)
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const atRisk = await ned.customers.getAtRisk({ limit: 20 });
|
|
43
|
+
* console.log(atRisk.data.total_profit_at_risk);
|
|
44
|
+
*/
|
|
45
|
+
async getAtRisk(params = {}) {
|
|
46
|
+
return this.client.request('/customers/at-risk', {
|
|
47
|
+
params: {
|
|
48
|
+
limit: params.limit,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.js","sourceRoot":"","sources":["../../src/resources/customers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmFH;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAEzC;;;;;;OAMG;IACH,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA0B,oBAAoB,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW,CAAC,SAAoC,EAAE;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA2B,qBAAqB,EAAE;YAC1E,MAAM,EAAE;gBACN,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,CAAC,SAA0B,EAAE;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA0B,oBAAoB,EAAE;YACxE,MAAM,EAAE;gBACN,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marketing Resource - Marketing metrics and ad performance
|
|
3
|
+
*/
|
|
4
|
+
import type { NedClient } from '../client.js';
|
|
5
|
+
import type { Period } from './analytics.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for getMetrics
|
|
8
|
+
*/
|
|
9
|
+
export interface GetMarketingMetricsParams {
|
|
10
|
+
period?: Period;
|
|
11
|
+
view_type?: 'summary' | 'daily' | 'weekly' | 'monthly';
|
|
12
|
+
limit?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parameters for getAds
|
|
16
|
+
*/
|
|
17
|
+
export interface GetAdsParams {
|
|
18
|
+
period?: Period;
|
|
19
|
+
platform?: 'meta' | 'google';
|
|
20
|
+
limit?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Marketing metrics response
|
|
24
|
+
*/
|
|
25
|
+
export interface MarketingMetricsResponse {
|
|
26
|
+
data: {
|
|
27
|
+
view_type: string;
|
|
28
|
+
period: string;
|
|
29
|
+
count: number | null;
|
|
30
|
+
metrics: Record<string, unknown>;
|
|
31
|
+
comparison: Record<string, unknown> | null;
|
|
32
|
+
};
|
|
33
|
+
metadata: {
|
|
34
|
+
source: string;
|
|
35
|
+
period: string;
|
|
36
|
+
view_type: string;
|
|
37
|
+
requested_at: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Ads performance response
|
|
42
|
+
*/
|
|
43
|
+
export interface AdsPerformanceResponse {
|
|
44
|
+
data: {
|
|
45
|
+
ads_count: number;
|
|
46
|
+
ads: Array<{
|
|
47
|
+
platform: string;
|
|
48
|
+
ad_id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
campaign_id: string | null;
|
|
51
|
+
ad_set_id: string | null;
|
|
52
|
+
status: string;
|
|
53
|
+
impressions: number;
|
|
54
|
+
clicks: number;
|
|
55
|
+
spend: string;
|
|
56
|
+
conversions: number;
|
|
57
|
+
conversion_value: string;
|
|
58
|
+
ctr: string | null;
|
|
59
|
+
cpc: string | null;
|
|
60
|
+
roas: string | null;
|
|
61
|
+
}>;
|
|
62
|
+
connected_platforms: {
|
|
63
|
+
meta: Array<{
|
|
64
|
+
id: string;
|
|
65
|
+
account_id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
}>;
|
|
68
|
+
google: Array<{
|
|
69
|
+
id: string;
|
|
70
|
+
customer_id: string;
|
|
71
|
+
name: string;
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
metadata: {
|
|
76
|
+
period: string;
|
|
77
|
+
platform_filter: string;
|
|
78
|
+
date_range: {
|
|
79
|
+
start: string;
|
|
80
|
+
end: string;
|
|
81
|
+
};
|
|
82
|
+
limit: number;
|
|
83
|
+
requested_at: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Marketing resource for marketing metrics and ad performance
|
|
88
|
+
*/
|
|
89
|
+
export declare class MarketingResource {
|
|
90
|
+
private client;
|
|
91
|
+
constructor(client: NedClient);
|
|
92
|
+
/**
|
|
93
|
+
* Get marketing efficiency metrics (MER, CAC, ROAS)
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const metrics = await ned.marketing.getMetrics({ period: 'this_month' });
|
|
97
|
+
* console.log(metrics.data.metrics);
|
|
98
|
+
*/
|
|
99
|
+
getMetrics(params?: GetMarketingMetricsParams): Promise<MarketingMetricsResponse>;
|
|
100
|
+
/**
|
|
101
|
+
* Get ad performance data across connected platforms
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const ads = await ned.marketing.getAds({ period: 'last_30_days', platform: 'meta' });
|
|
105
|
+
* console.log(ads.data.ads);
|
|
106
|
+
*/
|
|
107
|
+
getAds(params?: GetAdsParams): Promise<AdsPerformanceResponse>;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=marketing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketing.d.ts","sourceRoot":"","sources":["../../src/resources/marketing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,UAAU,EAAE,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C;QACxB,UAAU,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3C,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAErC;;;;;;OAMG;IACG,UAAU,CAAC,MAAM,GAAE,yBAA8B,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAU3F;;;;;;OAMG;IACG,MAAM,CAAC,MAAM,GAAE,YAAiB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CASzE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marketing Resource - Marketing metrics and ad performance
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Marketing resource for marketing metrics and ad performance
|
|
6
|
+
*/
|
|
7
|
+
export class MarketingResource {
|
|
8
|
+
client;
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get marketing efficiency metrics (MER, CAC, ROAS)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const metrics = await ned.marketing.getMetrics({ period: 'this_month' });
|
|
17
|
+
* console.log(metrics.data.metrics);
|
|
18
|
+
*/
|
|
19
|
+
async getMetrics(params = {}) {
|
|
20
|
+
return this.client.request('/marketing/metrics', {
|
|
21
|
+
params: {
|
|
22
|
+
period: params.period,
|
|
23
|
+
view_type: params.view_type,
|
|
24
|
+
limit: params.limit,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get ad performance data across connected platforms
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const ads = await ned.marketing.getAds({ period: 'last_30_days', platform: 'meta' });
|
|
33
|
+
* console.log(ads.data.ads);
|
|
34
|
+
*/
|
|
35
|
+
async getAds(params = {}) {
|
|
36
|
+
return this.client.request('/marketing/ads', {
|
|
37
|
+
params: {
|
|
38
|
+
period: params.period,
|
|
39
|
+
platform: params.platform,
|
|
40
|
+
limit: params.limit,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=marketing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marketing.js","sourceRoot":"","sources":["../../src/resources/marketing.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8EH;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACR;IAApB,YAAoB,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAEzC;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoC,EAAE;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAA2B,oBAAoB,EAAE;YACzE,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,SAAuB,EAAE;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAyB,gBAAgB,EAAE;YACnE,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ned-ai/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for the Ned AI API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ned",
|
|
21
|
+
"ai",
|
|
22
|
+
"sdk",
|
|
23
|
+
"shopify",
|
|
24
|
+
"analytics",
|
|
25
|
+
"api"
|
|
26
|
+
],
|
|
27
|
+
"author": "Ned AI",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.11.0",
|
|
31
|
+
"typescript": "^5.3.3"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.0.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/ned-ai/ned.git",
|
|
42
|
+
"directory": "packages/sdk"
|
|
43
|
+
}
|
|
44
|
+
}
|