@infigo-official/types-for-pricing-script 1.0.2 → 1.0.4

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 CHANGED
@@ -1,20 +1,437 @@
1
1
  # Types for Pricing Script
2
2
 
3
- Type definitions for the Pricing Script scripting interface.
3
+ Type definitions for the Infigo Pricing Script scripting interface.
4
+
5
+ ![Version](https://img.shields.io/badge/version-1.0.3-blue)
6
+ ![TypeScript](https://img.shields.io/badge/typescript-4.9.5-blue)
7
+ ![License](https://img.shields.io/badge/license-MIT-green)
8
+ ![npm](https://img.shields.io/npm/v/@infigo-official/types-for-pricing-script)
4
9
 
5
10
  Full documentation is available [here](https://infigo-official.github.io/types-for-pricing-scripts/).
6
11
 
7
- Use and install the package to get the best experience and IntelliSense support within our IDE.
8
- Choose dev dependencies if you are developing in Javascript or our code will not be reused in another project.
12
+ ## Overview
13
+
14
+ **Types for Pricing Script** provides TypeScript type definitions for the Infigo Pricing Script engine. These definitions enable full IntelliSense support, type checking, and documentation within your IDE when developing pricing scripts.
15
+
16
+ ## Features
17
+
18
+ - **Complete Type Definitions**: Full coverage of the Pricing Script API
19
+ - **IntelliSense Support**: Get autocomplete and inline documentation in your IDE
20
+ - **Type Safety**: Catch errors at development time before deploying scripts
21
+ - **Comprehensive Examples**: Real-world pricing script examples
22
+ - **Helper Methods**: Built-in utilities for common pricing calculations
23
+
24
+ ## Installation
9
25
 
10
26
  ```bash
11
- npm init
27
+ # Initialize a new project (if needed)
28
+ npm init -y
12
29
 
13
- # install as dev dependencies
30
+ # Install as dev dependency (recommended)
14
31
  npm i -D @infigo-official/types-for-pricing-script
15
32
 
16
- # ... or ...
17
-
18
- # install as dependencies
33
+ # Or install as regular dependency
19
34
  npm i @infigo-official/types-for-pricing-script
20
- ```
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### 1. Create a TypeScript Configuration
40
+
41
+ Create `tsconfig.json` in your project:
42
+
43
+ ```json
44
+ {
45
+ "compilerOptions": {
46
+ "target": "ES5",
47
+ "lib": ["ES6"],
48
+ "module": "CommonJS",
49
+ "strict": true,
50
+ "esModuleInterop": true
51
+ },
52
+ "include": ["src/**/*"]
53
+ }
54
+ ```
55
+
56
+ ### 2. Write Your First Pricing Script
57
+
58
+ Create `src/pricing-script.ts`:
59
+
60
+ ```typescript
61
+ // Basic pricing script example
62
+ function calculatePrice(): number {
63
+ // Start with the base price
64
+ let price = Item.Price;
65
+
66
+ // Apply tier pricing if available
67
+ if (Item.PricingTiers.length > 0) {
68
+ const tier = HelperMethods.FindTier(Item.Quantity, Item.PricingTiers);
69
+ if (tier) {
70
+ price = tier.Price;
71
+ }
72
+ }
73
+
74
+ // Add attribute adjustments
75
+ price += HelperMethods.GetAttributePriceAdjustment(Item.Quantity);
76
+
77
+ // Log the final price
78
+ console(`Final price: $${price.toFixed(2)}`);
79
+
80
+ return price;
81
+ }
82
+
83
+ // Return the calculated price
84
+ return calculatePrice();
85
+ ```
86
+
87
+ ### 3. Get IntelliSense
88
+
89
+ Your IDE will now provide:
90
+ - Autocomplete for `Item`, `Session`, `CheckoutItem`, `Configuration`, `HelperMethods`
91
+ - Type information on hover
92
+ - Parameter hints for methods
93
+ - Documentation from JSDoc comments
94
+
95
+ ## API Reference
96
+
97
+ ### Global Objects
98
+
99
+ | Object | Description |
100
+ |--------|-------------|
101
+ | `Item` | The main product item being priced with all its properties and methods |
102
+ | `Session` | Session-level data including cart items and customer information |
103
+ | `CheckoutItem` | Checkout context with shipping addresses and customer details |
104
+ | `Configuration` | Script configuration and parameters |
105
+ | `HelperMethods` | Utility functions for pricing calculations |
106
+
107
+ ### Output Functions
108
+
109
+ | Function | Description |
110
+ |----------|-------------|
111
+ | `debug(message)` | Debug messages (admin testing only) |
112
+ | `alert(message)` | Information messages shown to users |
113
+ | `warning(message)` | Warning messages shown to users |
114
+ | `error(message)` | Error messages shown to users |
115
+ | `console(message)` | Console logging for debugging |
116
+
117
+ ### Item Properties
118
+
119
+ <details>
120
+ <summary><strong>Click to expand full Item properties list</strong></summary>
121
+
122
+ #### Pricing Properties
123
+ | Property | Type | Description |
124
+ |----------|------|-------------|
125
+ | `Price` | `number` | Base product variant price |
126
+ | `OldPrice` | `number` | Previous price for comparison |
127
+ | `UnitPrice` | `number` | Calculated unit price |
128
+ | `FinalPrice` | `number` | Final calculated price |
129
+ | `ProductCost` | `number` | Production/acquisition cost |
130
+ | `SpecialPrice` | `number` | Promotional price |
131
+ | `AdditionalShippingCharge` | `number` | Shipping surcharge |
132
+
133
+ #### Product Information
134
+ | Property | Type | Description |
135
+ |----------|------|-------------|
136
+ | `ProductName` | `string` | Display name |
137
+ | `Sku` | `string` | Product SKU |
138
+ | `ActualSku` | `string` | SKU including combinations |
139
+ | `Categories` | `string[]` | Product categories |
140
+ | `Tags` | `string[]` | Product tags |
141
+ | `Weight`, `Width`, `Height`, `Length` | `number` | Physical dimensions |
142
+
143
+ #### Quantity & Packaging
144
+ | Property | Type | Description |
145
+ |----------|------|-------------|
146
+ | `Quantity` | `number` | Order quantity |
147
+ | `PackQuantity` | `number` | Pack-based quantity |
148
+ | `IsBatch` | `boolean` | Batch job indicator |
149
+ | `NumberOfPages` | `number` | Pages in document |
150
+ | `NumberOfRecords` | `number` | Records count |
151
+
152
+ #### Pricing Tiers
153
+ | Property | Type | Description |
154
+ |----------|------|-------------|
155
+ | `PricingTiers` | `Tier[]` | Standard pricing tiers |
156
+ | `BatchTiers` | `Tier[]` | Batch pricing tiers |
157
+ | `PricePerRecord` | `number` | Per-record pricing |
158
+
159
+ #### Customer Information
160
+ | Property | Type | Description |
161
+ |----------|------|-------------|
162
+ | `Email` | `string` | Customer email |
163
+ | `CustomerRoles` | `string[]` | Customer role assignments |
164
+ | `Department` | `string` | Customer department |
165
+ | `DiscountCode` | `string` | Applied discount code |
166
+
167
+ #### Attributes
168
+ | Property | Type | Description |
169
+ |----------|------|-------------|
170
+ | `Attributes` | `Attribute[]` | Product attributes with values |
171
+
172
+ </details>
173
+
174
+ ### Item Methods
175
+
176
+ | Method | Returns | Description |
177
+ |--------|---------|-------------|
178
+ | `getFileInfo(attributeId, readContent?)` | `FileInfo` | Get information about uploaded files |
179
+ | `getAttributeValue(attributeName)` | `string` | Get attribute value by name |
180
+ | `setAttributeValue(attributeName, value)` | `void` | Set attribute value |
181
+ | `getGlobalFileContent(filename)` | `string[]` | Load global configuration files |
182
+ | `getGlobalFileCsvContent(filename)` | `string[][]` | Load CSV data from global files |
183
+
184
+ ### Helper Methods
185
+
186
+ | Method | Description |
187
+ |--------|-------------|
188
+ | `FindTier(quantity, tiers, roles?)` | Find appropriate pricing tier |
189
+ | `GetAttributePriceAdjustment(quantity, roles?)` | Calculate total attribute adjustments |
190
+ | `InterpolatePrice(quantity, tiers)` | Interpolate prices between tiers |
191
+ | `CSV.parse(csv, options?)` | Parse CSV string to 2D array |
192
+ | `CSV.stringify(data, options?)` | Convert 2D array to CSV string |
193
+ | `LogObject(data)` | Log object properties for debugging |
194
+ | `Contains(array, value)` | Check if array contains value |
195
+ | `IsObject(item)` / `IsArray(item)` | Type checking utilities |
196
+ | `MergeObject(target, source)` | Deep merge objects |
197
+
198
+ ## Examples
199
+
200
+ ### Basic Pricing
201
+
202
+ ```typescript
203
+ // Simple price calculation with attribute adjustments
204
+ function calculatePrice(): number {
205
+ let price = Item.Price;
206
+ price += HelperMethods.GetAttributePriceAdjustment(Item.Quantity);
207
+ return price;
208
+ }
209
+
210
+ return calculatePrice();
211
+ ```
212
+
213
+ ### Tier-Based Pricing
214
+
215
+ ```typescript
216
+ // Quantity-based tier pricing
217
+ function calculatePrice(): number {
218
+ const tier = HelperMethods.FindTier(
219
+ Item.Quantity,
220
+ Item.PricingTiers,
221
+ Item.CustomerRoles
222
+ );
223
+
224
+ if (tier) {
225
+ return tier.Price + HelperMethods.GetAttributePriceAdjustment(Item.Quantity);
226
+ }
227
+
228
+ return Item.Price;
229
+ }
230
+
231
+ return calculatePrice();
232
+ ```
233
+
234
+ ### Customer Role Pricing
235
+
236
+ ```typescript
237
+ // Different prices for different customer roles
238
+ function calculatePrice(): number {
239
+ let price = Item.Price;
240
+
241
+ // Check for wholesale customer
242
+ if (HelperMethods.Contains(Item.CustomerRoles, "Wholesale")) {
243
+ price *= 0.80; // 20% wholesale discount
244
+ alert("Wholesale discount applied: 20% off");
245
+ }
246
+
247
+ // Check for VIP customer
248
+ if (HelperMethods.Contains(Item.CustomerRoles, "VIP")) {
249
+ price *= 0.90; // Additional 10% VIP discount
250
+ alert("VIP discount applied: 10% off");
251
+ }
252
+
253
+ return price;
254
+ }
255
+
256
+ return calculatePrice();
257
+ ```
258
+
259
+ ### CSV-Based Pricing
260
+
261
+ ```typescript
262
+ // Look up prices from a CSV file
263
+ function calculatePrice(): number {
264
+ const csvData = Item.getGlobalFileCsvContent("pricing-matrix.csv");
265
+
266
+ if (!csvData || csvData.length === 0) {
267
+ warning("Pricing matrix not found, using default price");
268
+ return Item.Price;
269
+ }
270
+
271
+ // Find matching row based on attributes
272
+ const size = Item.getAttributeValue("Size");
273
+ const material = Item.getAttributeValue("Material");
274
+
275
+ for (let i = 1; i < csvData.length; i++) {
276
+ const row = csvData[i];
277
+ if (row[0] === size && row[1] === material) {
278
+ return parseFloat(row[2]); // Price column
279
+ }
280
+ }
281
+
282
+ return Item.Price;
283
+ }
284
+
285
+ return calculatePrice();
286
+ ```
287
+
288
+ ### File-Based Pricing
289
+
290
+ ```typescript
291
+ // Price based on uploaded file characteristics
292
+ function calculatePrice(): number {
293
+ let price = Item.Price;
294
+
295
+ const fileInfo = Item.getFileInfo("artwork", true);
296
+
297
+ if (fileInfo.Error) {
298
+ return price;
299
+ }
300
+
301
+ // Add per-page fee for PDFs
302
+ if (fileInfo.MimeType === "application/pdf") {
303
+ price += fileInfo.NumberOfPages * 0.25;
304
+ console(`Added $${(fileInfo.NumberOfPages * 0.25).toFixed(2)} for ${fileInfo.NumberOfPages} pages`);
305
+ }
306
+
307
+ // Add size-based fee
308
+ const sizeMB = fileInfo.Size / (1024 * 1024);
309
+ if (sizeMB > 5) {
310
+ price += (sizeMB - 5) * 1.00; // $1 per MB over 5MB
311
+ }
312
+
313
+ return price;
314
+ }
315
+
316
+ return calculatePrice();
317
+ ```
318
+
319
+ ## Project Structure
320
+
321
+ ```
322
+ types-for-pricing-script/
323
+ ├── v1/ # Version 1 type definitions
324
+ │ ├── OrderItem/
325
+ │ │ ├── Item.d.ts # Main Item interface
326
+ │ │ ├── Attribute.d.ts # Attribute definitions
327
+ │ │ ├── Tier.d.ts # Pricing tier definitions
328
+ │ │ └── Version.d.ts # Version/job management
329
+ │ ├── File/
330
+ │ │ └── FileInfo.d.ts # File information interface
331
+ │ ├── Configuration/
332
+ │ │ └── Configuration.d.ts # Script configuration
333
+ │ ├── Output/
334
+ │ │ └── Output.d.ts # Output functions
335
+ │ ├── Helpers/
336
+ │ │ └── Helpers.d.ts # Helper methods
337
+ │ ├── SessionItem/
338
+ │ │ └── Session.d.ts # Session interface
339
+ │ ├── CheckoutItem/
340
+ │ │ └── CheckoutItem.d.ts # Checkout interface
341
+ │ └── index.d.ts # Main entry point
342
+ ├── docs/ # Documentation site
343
+ ├── package.json
344
+ ├── README.md
345
+ └── QUICKSTART.md
346
+ ```
347
+
348
+ ## Development
349
+
350
+ ### Building Documentation
351
+
352
+ ```bash
353
+ # Generate TypeDoc documentation
354
+ npm run docs
355
+
356
+ # Serve documentation locally
357
+ npm start
358
+ ```
359
+
360
+ ### Running Examples
361
+
362
+ ```bash
363
+ cd examples
364
+ npm install
365
+ npm run build
366
+ ```
367
+
368
+ ## Supported File Types
369
+
370
+ The FileInfo interface supports these file types:
371
+
372
+ | Type | Properties Available |
373
+ |------|---------------------|
374
+ | PDF | Size, NumberOfPages, Dimensions, Content |
375
+ | JPEG/PNG/GIF/BMP/TIFF | Size, Dimensions |
376
+ | Text/CSV | Size, NumberOfRecords, Content |
377
+
378
+ **Note**: File content is only available for files under 50KB. Page count is limited to PDFs under 10MB.
379
+
380
+ ## Troubleshooting
381
+
382
+ ### Script Not Returning Value
383
+ Ensure your script returns a number. If an exception occurs, the system falls back to the normal price.
384
+
385
+ ```typescript
386
+ // Always return a number
387
+ return calculatePrice();
388
+ ```
389
+
390
+ ### IntelliSense Not Working
391
+ 1. Ensure the package is installed: `npm i -D @infigo-official/types-for-pricing-script`
392
+ 2. Restart your IDE
393
+ 3. Check that `tsconfig.json` is configured correctly
394
+
395
+ ### Type Errors
396
+ The types are read-only where appropriate. Use the provided methods to modify values:
397
+
398
+ ```typescript
399
+ // Wrong - Item.Price is read-only for assignment
400
+ // Item.Price = 100;
401
+
402
+ // Correct - return your calculated price
403
+ return 100;
404
+
405
+ // Correct - use setAttributeValue for attributes
406
+ Item.setAttributeValue("custom_field", "value");
407
+ ```
408
+
409
+ ## Changelog
410
+
411
+ ### v1.0.3
412
+ - Updated documentation
413
+ - Added more examples
414
+
415
+ ### v1.0.2
416
+ - Added CSV helper methods
417
+ - Improved type definitions
418
+
419
+ ### v1.0.1
420
+ - Initial release
421
+ - Core type definitions
422
+
423
+ ## License
424
+
425
+ MIT
426
+
427
+ ## Contributing
428
+
429
+ This package is maintained by the Infigo development team.
430
+
431
+ For issues or questions, please visit:
432
+ - [GitHub Issues](https://github.com/Infigo-Official/types-for-pricing-scripts/issues)
433
+ - [Documentation](https://infigo-official.github.io/types-for-pricing-script/)
434
+
435
+ ---
436
+
437
+ **Built for the Infigo Platform**
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@infigo-official/types-for-pricing-script",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Type definitions for Pricing Script Scripting",
5
5
  "types": "v1/index.d.ts",
6
6
  "devDependencies": {
7
- "typedoc": "^0.24.8",
8
7
  "typescript": "^4.9.5"
9
8
  },
10
9
  "scripts": {
11
- "docs": "npx typedoc",
12
- "start": "npx http-server docs -p 3000 -o"
10
+ "docs": "cd docusaurus-docs && npm install && npm run build",
11
+ "docs:dev": "cd docusaurus-docs && npm start",
12
+ "docs:build": "cd docusaurus-docs && npm run build"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",