@neo-edi/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.
package/README.md ADDED
@@ -0,0 +1,203 @@
1
+ # @neo-edi/sdk
2
+
3
+ Official TypeScript SDK for the Neo-EDI platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @neo-edi/sdk
9
+ # or
10
+ pnpm add @neo-edi/sdk
11
+ # or
12
+ yarn add @neo-edi/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { NeoEdiClient } from '@neo-edi/sdk';
19
+
20
+ const client = new NeoEdiClient({
21
+ baseUrl: 'https://api.neo-edi.com',
22
+ apiKey: 'nedk_xxxxxxxxxxxx'
23
+ });
24
+ ```
25
+
26
+ ## Customers
27
+
28
+ ```typescript
29
+ // List customers
30
+ const customers = await client.customers.list({
31
+ isActive: true,
32
+ limit: 50
33
+ });
34
+
35
+ // Get customer
36
+ const customer = await client.customers.get('ACME-001');
37
+
38
+ // Create customer
39
+ const newCustomer = await client.customers.create({
40
+ customerId: 'ACME-001',
41
+ customerName: 'Acme Corporation',
42
+ customerMetadata: { industry: 'retail' }
43
+ });
44
+
45
+ // Update customer
46
+ const updated = await client.customers.update('ACME-001', {
47
+ customerName: 'Acme Corp'
48
+ });
49
+
50
+ // Delete customer
51
+ await client.customers.delete('ACME-001');
52
+ ```
53
+
54
+ ## Partner-Customer Relationships
55
+
56
+ ```typescript
57
+ // Register customer with multiple partners
58
+ const result = await client.partnerCustomers.register({
59
+ customerId: 'ACME-001',
60
+ tradingPartnerIds: ['PARTNER-001', 'PARTNER-002'],
61
+ isActive: true
62
+ });
63
+ ```
64
+
65
+ ## Mapping Templates
66
+
67
+ ```typescript
68
+ // List templates
69
+ const templates = await client.mappingTemplates.list({
70
+ isPublic: true,
71
+ targetTable: 'edi_852_headers'
72
+ });
73
+
74
+ // Create template
75
+ const template = await client.mappingTemplates.create({
76
+ name: 'My 852 Template',
77
+ targetTable: 'edi_852_headers',
78
+ mappingConfig: {
79
+ 'CSV Column': 'db_column'
80
+ }
81
+ });
82
+
83
+ // Update template
84
+ await client.mappingTemplates.update('template-id', {
85
+ name: 'Updated Name'
86
+ });
87
+ ```
88
+
89
+ ## CSV Ingestion
90
+
91
+ ```typescript
92
+ // Browser - File input
93
+ const fileInput = document.querySelector<HTMLInputElement>('input[type="file"]');
94
+ const file = fileInput?.files?.[0];
95
+
96
+ if (file) {
97
+ const result = await client.ingest.uploadCsv(file, {
98
+ partnerId: 'PARTNER-001',
99
+ mappingConfig: {
100
+ id: 'config-1',
101
+ version: 1,
102
+ tables: {
103
+ edi_852_headers: {
104
+ batchSize: 500,
105
+ mapping: { 'Report Date': 'report_date' },
106
+ defaults: {}
107
+ }
108
+ }
109
+ }
110
+ });
111
+ }
112
+
113
+ // Dry run (validation only)
114
+ const dryRunResult = await client.ingest.dryRun(file, options);
115
+ if (!dryRunResult.valid) {
116
+ console.error('Validation errors:', dryRunResult.errors);
117
+ }
118
+ ```
119
+
120
+ ### Node.js File Upload
121
+
122
+ ```typescript
123
+ import { readFileSync } from 'fs';
124
+
125
+ const buffer = readFileSync('data.csv');
126
+ const blob = new Blob([buffer], { type: 'text/csv' });
127
+
128
+ await client.ingest.uploadCsv(blob, options);
129
+ ```
130
+
131
+ ## GraphQL
132
+
133
+ ```typescript
134
+ import { Queries } from '@neo-edi/sdk';
135
+
136
+ // Using pre-built queries
137
+ const headers = await client.graphql.query(
138
+ Queries.GET_EDI_852_HEADERS,
139
+ { filter: { status: 'pending' } }
140
+ );
141
+
142
+ // Custom query
143
+ const data = await client.graphql.query<{ edi852Headers: Edi852Header[] }>(`
144
+ query GetHeaders($filter: Edi852HeaderFilterInput) {
145
+ edi852Headers(filter: $filter) {
146
+ id
147
+ documentId
148
+ reportDate
149
+ status
150
+ }
151
+ }
152
+ `, { filter: { vendorPartnerId: 'VENDOR-001' } });
153
+ ```
154
+
155
+ ## Error Handling
156
+
157
+ ```typescript
158
+ import { NeoEdiApiError, NeoEdiNetworkError } from '@neo-edi/sdk';
159
+
160
+ try {
161
+ await client.customers.get('non-existent');
162
+ } catch (error) {
163
+ if (error instanceof NeoEdiApiError) {
164
+ console.error(`API Error: ${error.message}`);
165
+ console.error(`Status: ${error.statusCode}`);
166
+ console.error(`Code: ${error.code}`);
167
+ } else if (error instanceof NeoEdiNetworkError) {
168
+ console.error(`Network Error: ${error.message}`);
169
+ }
170
+ }
171
+ ```
172
+
173
+ ## Configuration
174
+
175
+ ```typescript
176
+ const client = new NeoEdiClient({
177
+ baseUrl: 'https://api.neo-edi.com',
178
+ apiKey: 'nedk_xxxxxxxxxxxx',
179
+ timeout: 60000, // 60 seconds
180
+ headers: {
181
+ 'X-Custom-Header': 'value'
182
+ }
183
+ });
184
+ ```
185
+
186
+ ## TypeScript Types
187
+
188
+ All types are exported for use:
189
+
190
+ ```typescript
191
+ import type {
192
+ EdiCustomer,
193
+ EdiPartner,
194
+ Edi852Header,
195
+ EdiMappingTemplate,
196
+ CsvHeaderMappingCollection,
197
+ ApiResponse
198
+ } from '@neo-edi/sdk';
199
+ ```
200
+
201
+ ## License
202
+
203
+ MIT
@@ -0,0 +1,289 @@
1
+ import { ListCustomersParams, EdiCustomer, CreateCustomerRequest, UpdateCustomerRequest, RegisterPartnerCustomerRequest, PartnerCustomerRegistrationResult, ListMappingTemplatesParams, EdiMappingTemplate, CreateMappingTemplateRequest, UpdateMappingTemplateRequest, CsvHeaderMappingCollection, CsvDataTransformationConfig, IngestCsvResult, DryRunResult } from '@neo-edi/types';
2
+ export { Address, ApiResponse, CreateCustomerRequest, CreateMappingTemplateRequest, CreatePartnerRequest, CsvDataTransformationConfig, CsvHeaderMappingCollection, CsvHeaderMappingConfig, CsvHeaderTableEntry, DryRunResult, Edi852DeliverySummary, Edi852Header, Edi852HeaderFilter, Edi852Item, Edi852Location, Edi852Status, EdiCustomer, EdiMappingTemplate, EdiPartner, EdiPartnerCustomer, IngestCsvResult, ListCustomersParams, ListMappingTemplatesParams, PaginatedResponse, PartnerCustomerRegistrationResult, RegisterPartnerCustomerRequest, UpdateCustomerRequest, UpdateMappingTemplateRequest, UpdatePartnerRequest } from '@neo-edi/types';
3
+
4
+ /**
5
+ * Base HTTP client for the SDK
6
+ */
7
+ interface HttpClientConfig {
8
+ baseUrl: string;
9
+ apiKey: string;
10
+ timeout?: number;
11
+ headers?: Record<string, string>;
12
+ }
13
+ interface RequestOptions {
14
+ method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
15
+ path: string;
16
+ body?: unknown;
17
+ query?: Record<string, string | number | boolean | undefined>;
18
+ headers?: Record<string, string>;
19
+ }
20
+ declare class HttpClient {
21
+ private baseUrl;
22
+ private apiKey;
23
+ private timeout;
24
+ private defaultHeaders;
25
+ constructor(config: HttpClientConfig);
26
+ request<T>(options: RequestOptions): Promise<T>;
27
+ private buildUrl;
28
+ private parseResponse;
29
+ get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
30
+ post<T>(path: string, body?: unknown): Promise<T>;
31
+ patch<T>(path: string, body?: unknown): Promise<T>;
32
+ put<T>(path: string, body?: unknown): Promise<T>;
33
+ delete<T>(path: string): Promise<T>;
34
+ }
35
+
36
+ /**
37
+ * Customers resource
38
+ */
39
+
40
+ declare class CustomersResource {
41
+ private http;
42
+ constructor(http: HttpClient);
43
+ /**
44
+ * List all customers
45
+ */
46
+ list(params?: ListCustomersParams): Promise<EdiCustomer[]>;
47
+ /**
48
+ * Get a customer by ID
49
+ */
50
+ get(customerId: string): Promise<EdiCustomer>;
51
+ /**
52
+ * Create a new customer
53
+ */
54
+ create(data: CreateCustomerRequest): Promise<EdiCustomer>;
55
+ /**
56
+ * Update a customer
57
+ */
58
+ update(customerId: string, data: UpdateCustomerRequest): Promise<EdiCustomer>;
59
+ /**
60
+ * Delete a customer
61
+ */
62
+ delete(customerId: string): Promise<void>;
63
+ }
64
+
65
+ /**
66
+ * Partner-Customers resource
67
+ */
68
+
69
+ declare class PartnerCustomersResource {
70
+ private http;
71
+ constructor(http: HttpClient);
72
+ /**
73
+ * Register customer-partner relationships
74
+ * Creates or activates relationships between a customer and multiple trading partners
75
+ */
76
+ register(data: RegisterPartnerCustomerRequest): Promise<PartnerCustomerRegistrationResult>;
77
+ }
78
+
79
+ /**
80
+ * Mapping Templates resource
81
+ */
82
+
83
+ declare class MappingTemplatesResource {
84
+ private http;
85
+ constructor(http: HttpClient);
86
+ /**
87
+ * List all mapping templates
88
+ */
89
+ list(params?: ListMappingTemplatesParams): Promise<EdiMappingTemplate[]>;
90
+ /**
91
+ * Get a mapping template by ID
92
+ */
93
+ get(templateId: string): Promise<EdiMappingTemplate>;
94
+ /**
95
+ * Create a new mapping template
96
+ */
97
+ create(data: CreateMappingTemplateRequest): Promise<EdiMappingTemplate>;
98
+ /**
99
+ * Update a mapping template
100
+ */
101
+ update(templateId: string, data: UpdateMappingTemplateRequest): Promise<EdiMappingTemplate>;
102
+ /**
103
+ * Delete a mapping template
104
+ */
105
+ delete(templateId: string): Promise<void>;
106
+ }
107
+
108
+ /**
109
+ * Ingest resource for CSV data ingestion
110
+ */
111
+
112
+ interface UploadCsvOptions {
113
+ partnerId: string;
114
+ mappingConfig: CsvHeaderMappingCollection;
115
+ transformationConfig?: CsvDataTransformationConfig;
116
+ }
117
+ /**
118
+ * File input type for CSV upload
119
+ * In browser: File or Blob
120
+ * In Node.js: Use `new Blob([buffer])` to convert Buffer to Blob
121
+ */
122
+ type CsvFileInput = File | Blob;
123
+ declare class IngestResource {
124
+ private http;
125
+ constructor(http: HttpClient);
126
+ /**
127
+ * Upload a CSV file for ingestion
128
+ *
129
+ * @example Browser
130
+ * ```typescript
131
+ * const input = document.querySelector('input[type="file"]');
132
+ * const file = input.files[0];
133
+ * await client.ingest.uploadCsv(file, options);
134
+ * ```
135
+ *
136
+ * @example Node.js
137
+ * ```typescript
138
+ * import { readFileSync } from 'fs';
139
+ * const buffer = readFileSync('data.csv');
140
+ * const blob = new Blob([buffer], { type: 'text/csv' });
141
+ * await client.ingest.uploadCsv(blob, options);
142
+ * ```
143
+ */
144
+ uploadCsv(file: CsvFileInput, options: UploadCsvOptions): Promise<IngestCsvResult>;
145
+ /**
146
+ * Perform a dry run of CSV ingestion (validation only)
147
+ */
148
+ dryRun(file: CsvFileInput, options: UploadCsvOptions): Promise<DryRunResult>;
149
+ }
150
+
151
+ /**
152
+ * GraphQL resource for flexible queries
153
+ */
154
+
155
+ interface GraphQLRequestOptions {
156
+ operationName?: string;
157
+ }
158
+ declare class GraphQLResource {
159
+ private http;
160
+ constructor(http: HttpClient);
161
+ /**
162
+ * Execute a GraphQL query
163
+ */
164
+ query<T>(query: string, variables?: Record<string, unknown>, options?: GraphQLRequestOptions): Promise<T>;
165
+ /**
166
+ * Execute a GraphQL mutation
167
+ */
168
+ mutate<T>(mutation: string, variables?: Record<string, unknown>, options?: GraphQLRequestOptions): Promise<T>;
169
+ }
170
+ /**
171
+ * Pre-built GraphQL queries for common operations
172
+ */
173
+ declare const Queries: {
174
+ /**
175
+ * Get EDI 852 headers with filtering
176
+ */
177
+ GET_EDI_852_HEADERS: string;
178
+ /**
179
+ * Get a single EDI 852 header by ID with locations
180
+ */
181
+ GET_EDI_852_HEADER_BY_ID: string;
182
+ /**
183
+ * Get trading partner execution summaries
184
+ */
185
+ GET_EXECUTION_SUMMARIES: string;
186
+ };
187
+
188
+ /**
189
+ * Neo-EDI SDK Client
190
+ */
191
+
192
+ interface NeoEdiClientConfig {
193
+ /**
194
+ * Base URL of the Neo-EDI API
195
+ * @example "https://api.neo-edi.com"
196
+ */
197
+ baseUrl: string;
198
+ /**
199
+ * API key for authentication
200
+ * @example "nedk_live_xxxxxxxxxxxx"
201
+ */
202
+ apiKey: string;
203
+ /**
204
+ * Request timeout in milliseconds (default: 30000)
205
+ */
206
+ timeout?: number;
207
+ /**
208
+ * Additional headers to send with every request
209
+ */
210
+ headers?: Record<string, string>;
211
+ }
212
+ /**
213
+ * Neo-EDI SDK Client
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * const client = new NeoEdiClient({
218
+ * baseUrl: "https://api.neo-edi.com",
219
+ * apiKey: "nedk_live_xxxxxxxxxxxx"
220
+ * });
221
+ *
222
+ * // List customers
223
+ * const customers = await client.customers.list({ isActive: true });
224
+ *
225
+ * // Create a customer
226
+ * const customer = await client.customers.create({
227
+ * customerId: "ACME-001",
228
+ * customerName: "Acme Corporation"
229
+ * });
230
+ *
231
+ * // Upload CSV data
232
+ * const result = await client.ingest.uploadCsv(file, {
233
+ * partnerId: "PARTNER-001",
234
+ * mappingConfig: { ... }
235
+ * });
236
+ *
237
+ * // Run GraphQL query
238
+ * const data = await client.graphql.query(
239
+ * `query { edi852Headers { id reportDate } }`
240
+ * );
241
+ * ```
242
+ */
243
+ declare class NeoEdiClient {
244
+ private http;
245
+ /**
246
+ * Customer management operations
247
+ */
248
+ readonly customers: CustomersResource;
249
+ /**
250
+ * Partner-Customer relationship operations
251
+ */
252
+ readonly partnerCustomers: PartnerCustomersResource;
253
+ /**
254
+ * Mapping template operations
255
+ */
256
+ readonly mappingTemplates: MappingTemplatesResource;
257
+ /**
258
+ * CSV data ingestion operations
259
+ */
260
+ readonly ingest: IngestResource;
261
+ /**
262
+ * GraphQL query operations
263
+ */
264
+ readonly graphql: GraphQLResource;
265
+ constructor(config: NeoEdiClientConfig);
266
+ }
267
+
268
+ /**
269
+ * SDK error types
270
+ */
271
+ declare class NeoEdiError extends Error {
272
+ readonly code?: string | undefined;
273
+ readonly statusCode?: number | undefined;
274
+ readonly details?: Record<string, unknown> | undefined;
275
+ constructor(message: string, code?: string | undefined, statusCode?: number | undefined, details?: Record<string, unknown> | undefined);
276
+ }
277
+ declare class NeoEdiApiError extends NeoEdiError {
278
+ readonly statusCode: number;
279
+ constructor(message: string, statusCode: number, code?: string, details?: Record<string, unknown>);
280
+ }
281
+ declare class NeoEdiNetworkError extends NeoEdiError {
282
+ readonly cause?: Error | undefined;
283
+ constructor(message: string, cause?: Error | undefined);
284
+ }
285
+ declare class NeoEdiValidationError extends NeoEdiError {
286
+ constructor(message: string, details?: Record<string, unknown>);
287
+ }
288
+
289
+ export { type CsvFileInput, NeoEdiApiError, NeoEdiClient, type NeoEdiClientConfig, NeoEdiError, NeoEdiNetworkError, NeoEdiValidationError, Queries, type UploadCsvOptions };