@infigo-official/types-for-pricing-script 1.0.3 → 1.0.5
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 +426 -9
- package/package.json +1 -1
- package/v1/CheckoutItem/CheckoutItem.d.ts +3 -1
- package/v1/Configuration/Configuration.d.ts +2 -0
- package/v1/Helpers/Helpers.d.ts +2 -0
- package/v1/OrderItem/Item.d.ts +211 -18
- package/v1/Output/Output.d.ts +15 -10
- package/v1/SessionItem/Session.d.ts +3 -1
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
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
4
9
|
|
|
5
10
|
Full documentation is available [here](https://infigo-official.github.io/types-for-pricing-scripts/).
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
27
|
+
# Initialize a new project (if needed)
|
|
28
|
+
npm init -y
|
|
12
29
|
|
|
13
|
-
#
|
|
30
|
+
# Install as dev dependency (recommended)
|
|
14
31
|
npm i -D @infigo-official/types-for-pricing-script
|
|
15
32
|
|
|
16
|
-
#
|
|
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
|
@@ -213,9 +213,11 @@ declare interface CheckoutAddress {
|
|
|
213
213
|
* The checkout item object available in checkout pricing scripts.
|
|
214
214
|
* Represents comprehensive checkout information including all items being purchased,
|
|
215
215
|
* customer details, shipping information, and checkout context.
|
|
216
|
-
*
|
|
216
|
+
*
|
|
217
217
|
* This object provides complete checkout context for pricing calculations that
|
|
218
218
|
* need to consider shipping, customer information, and multi-item scenarios.
|
|
219
|
+
*
|
|
220
|
+
* @category Global Objects
|
|
219
221
|
*/
|
|
220
222
|
declare interface CheckoutItem {
|
|
221
223
|
/**
|
package/v1/Helpers/Helpers.d.ts
CHANGED
|
@@ -101,6 +101,8 @@ declare interface CsvHelper {
|
|
|
101
101
|
* Helper methods available in pricing scripts for common calculations and data manipulation
|
|
102
102
|
* These utilities extend the capabilities of pricing scripts and help create more flexible
|
|
103
103
|
* and maintainable pricing logic.
|
|
104
|
+
*
|
|
105
|
+
* @category Helper Methods
|
|
104
106
|
*/
|
|
105
107
|
declare interface HelperMethods {
|
|
106
108
|
/**
|
package/v1/OrderItem/Item.d.ts
CHANGED
|
@@ -17,9 +17,11 @@
|
|
|
17
17
|
* Represents the product variant being priced and provides access to all
|
|
18
18
|
* product information, attributes, pricing data, and methods for file handling
|
|
19
19
|
* and attribute management.
|
|
20
|
-
*
|
|
20
|
+
*
|
|
21
21
|
* This object is the primary interface for accessing product data and performing
|
|
22
22
|
* pricing calculations in pricing scripts.
|
|
23
|
+
*
|
|
24
|
+
* @category Global Objects
|
|
23
25
|
*/
|
|
24
26
|
declare interface Item {
|
|
25
27
|
/**
|
|
@@ -130,9 +132,13 @@ declare interface Item {
|
|
|
130
132
|
/**
|
|
131
133
|
* The weight of the item in the configured weight unit (typically grams or ounces).
|
|
132
134
|
* This value is used for shipping calculations and weight-based pricing.
|
|
133
|
-
*
|
|
135
|
+
*
|
|
134
136
|
* @example
|
|
135
|
-
*
|
|
137
|
+
* // Calculate shipping cost based on weight
|
|
138
|
+
* var weightInKg = Item.Weight / 1000;
|
|
139
|
+
* var shippingRate = 2.50; // $2.50 per kg
|
|
140
|
+
* var shippingCost = weightInKg * shippingRate;
|
|
141
|
+
* debug("Item weight: " + Item.Weight + "g, Shipping: $" + shippingCost);
|
|
136
142
|
*/
|
|
137
143
|
Weight: number;
|
|
138
144
|
|
|
@@ -140,10 +146,12 @@ declare interface Item {
|
|
|
140
146
|
* Indicates whether the weight can be set or modified for this item.
|
|
141
147
|
* Some products may have fixed weights that cannot be changed,
|
|
142
148
|
* while others allow weight adjustments based on attributes or custom settings.
|
|
143
|
-
*
|
|
149
|
+
*
|
|
144
150
|
* @example
|
|
145
|
-
* if (Item.CanSetWeight) {
|
|
146
|
-
*
|
|
151
|
+
* if (Item.CanSetWeight && Item.Weight > 5000) {
|
|
152
|
+
* debug("Heavy item detected - weight: " + Item.Weight + "g");
|
|
153
|
+
* // Apply heavy item surcharge
|
|
154
|
+
* return Item.Price + 10.00;
|
|
147
155
|
* }
|
|
148
156
|
*/
|
|
149
157
|
CanSetWeight: boolean;
|
|
@@ -152,9 +160,13 @@ declare interface Item {
|
|
|
152
160
|
* The Stock Keeping Unit (SKU) of the product variant.
|
|
153
161
|
* This is the unique identifier for the product variant and is used
|
|
154
162
|
* for inventory management and order processing.
|
|
155
|
-
*
|
|
163
|
+
*
|
|
156
164
|
* @example
|
|
157
|
-
*
|
|
165
|
+
* // Apply SKU-specific pricing rules
|
|
166
|
+
* if (Item.Sku.startsWith("PREMIUM-")) {
|
|
167
|
+
* debug("Premium product: " + Item.Sku);
|
|
168
|
+
* return Item.Price * 1.10; // 10% premium markup
|
|
169
|
+
* }
|
|
158
170
|
*/
|
|
159
171
|
Sku: string;
|
|
160
172
|
|
|
@@ -162,36 +174,52 @@ declare interface Item {
|
|
|
162
174
|
* The actual SKU based on the current attribute combination.
|
|
163
175
|
* If no attributes are selected, this will be the same as the product SKU.
|
|
164
176
|
* This value reflects the specific configuration of the product being priced.
|
|
165
|
-
*
|
|
177
|
+
*
|
|
166
178
|
* @example
|
|
167
|
-
*
|
|
179
|
+
* // Log the configured SKU for debugging
|
|
180
|
+
* debug("Base SKU: " + Item.Sku);
|
|
181
|
+
* debug("Configured SKU: " + Item.ActualSku);
|
|
182
|
+
* if (Item.ActualSku !== Item.Sku) {
|
|
183
|
+
* debug("Product has attribute variations");
|
|
184
|
+
* }
|
|
168
185
|
*/
|
|
169
186
|
ActualSku: string;
|
|
170
187
|
|
|
171
188
|
/**
|
|
172
189
|
* The width of the item in the configured dimension unit (typically inches or centimeters).
|
|
173
190
|
* This value is used for packaging calculations and dimensional pricing.
|
|
174
|
-
*
|
|
191
|
+
*
|
|
175
192
|
* @example
|
|
176
|
-
*
|
|
193
|
+
* // Calculate area-based pricing
|
|
194
|
+
* var area = Item.Width * Item.Height;
|
|
195
|
+
* var pricePerSquareUnit = 0.05;
|
|
196
|
+
* var areaCost = area * pricePerSquareUnit;
|
|
197
|
+
* debug("Area: " + area + " sq units, Cost: $" + areaCost);
|
|
177
198
|
*/
|
|
178
199
|
Width: number;
|
|
179
200
|
|
|
180
201
|
/**
|
|
181
202
|
* The height of the item in the configured dimension unit (typically inches or centimeters).
|
|
182
203
|
* This value is used for packaging calculations and dimensional pricing.
|
|
183
|
-
*
|
|
204
|
+
*
|
|
184
205
|
* @example
|
|
185
|
-
*
|
|
206
|
+
* // Check if item is oversized
|
|
207
|
+
* if (Item.Height > 48) {
|
|
208
|
+
* debug("Oversized item - adding handling fee");
|
|
209
|
+
* return Item.Price + 25.00;
|
|
210
|
+
* }
|
|
186
211
|
*/
|
|
187
212
|
Height: number;
|
|
188
213
|
|
|
189
214
|
/**
|
|
190
215
|
* The length of the item in the configured dimension unit (typically inches or centimeters).
|
|
191
216
|
* This value is used for packaging calculations and dimensional pricing.
|
|
192
|
-
*
|
|
217
|
+
*
|
|
193
218
|
* @example
|
|
194
|
-
*
|
|
219
|
+
* // Calculate volume for shipping
|
|
220
|
+
* var volume = Item.Width * Item.Height * Item.Length;
|
|
221
|
+
* var volumetricWeight = volume / 5000; // Standard divisor
|
|
222
|
+
* debug("Volumetric weight: " + volumetricWeight);
|
|
195
223
|
*/
|
|
196
224
|
Length: number;
|
|
197
225
|
|
|
@@ -199,9 +227,14 @@ declare interface Item {
|
|
|
199
227
|
* The name of the product as displayed to customers.
|
|
200
228
|
* This is the human-readable product name used in the user interface
|
|
201
229
|
* and order confirmations.
|
|
202
|
-
*
|
|
230
|
+
*
|
|
203
231
|
* @example
|
|
204
|
-
*
|
|
232
|
+
* debug("Processing order for: " + Item.ProductName);
|
|
233
|
+
* // Check for special product names
|
|
234
|
+
* if (Item.ProductName.indexOf("Rush") >= 0) {
|
|
235
|
+
* debug("Rush order product detected");
|
|
236
|
+
* return Item.Price * 1.50; // 50% rush fee
|
|
237
|
+
* }
|
|
205
238
|
*/
|
|
206
239
|
ProductName: string;
|
|
207
240
|
|
|
@@ -265,101 +298,261 @@ declare interface Item {
|
|
|
265
298
|
|
|
266
299
|
/**
|
|
267
300
|
* Whether this is a batch job
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* if (Item.IsBatch) {
|
|
304
|
+
* debug("Processing batch job with " + Item.NumberOfRecords + " records");
|
|
305
|
+
* var batchSetupFee = 25.00;
|
|
306
|
+
* return Item.Price + batchSetupFee;
|
|
307
|
+
* }
|
|
268
308
|
*/
|
|
269
309
|
IsBatch: boolean;
|
|
270
310
|
|
|
271
311
|
/**
|
|
272
312
|
* Number of pages (-1 if not valid)
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* if (Item.NumberOfPages > 0) {
|
|
316
|
+
* var perPageCost = 0.10;
|
|
317
|
+
* var pageCost = Item.NumberOfPages * perPageCost;
|
|
318
|
+
* debug("Document has " + Item.NumberOfPages + " pages, adding $" + pageCost);
|
|
319
|
+
* return Item.Price + pageCost;
|
|
320
|
+
* }
|
|
273
321
|
*/
|
|
274
322
|
NumberOfPages: number;
|
|
275
323
|
|
|
276
324
|
/**
|
|
277
325
|
* Number of records (-1 if not valid)
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* if (Item.NumberOfRecords > 0) {
|
|
329
|
+
* var perRecordCost = 0.05;
|
|
330
|
+
* var recordCost = Item.NumberOfRecords * perRecordCost;
|
|
331
|
+
* debug("Batch has " + Item.NumberOfRecords + " records");
|
|
332
|
+
* return Item.Price + recordCost;
|
|
333
|
+
* }
|
|
278
334
|
*/
|
|
279
335
|
NumberOfRecords: number;
|
|
280
336
|
|
|
281
337
|
/**
|
|
282
338
|
* Array of pricing tiers with Price, Quantity, and CustomerRole
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* // Find the best tier for the current quantity
|
|
342
|
+
* var tier = HelperMethods.FindTier(Item.Quantity, Item.PricingTiers, Item.CustomerRoles);
|
|
343
|
+
* if (tier) {
|
|
344
|
+
* debug("Using tier: " + tier.Quantity + " @ $" + tier.Price);
|
|
345
|
+
* return tier.Price * Item.Quantity;
|
|
346
|
+
* }
|
|
283
347
|
*/
|
|
284
348
|
PricingTiers: Tier[];
|
|
285
349
|
|
|
286
350
|
/**
|
|
287
351
|
* Array of batch tiers (same as PricingTiers but for batch tier table)
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* if (Item.IsBatch && Item.BatchTiers.length > 0) {
|
|
355
|
+
* var batchTier = HelperMethods.FindTier(Item.NumberOfRecords, Item.BatchTiers);
|
|
356
|
+
* if (batchTier) {
|
|
357
|
+
* debug("Batch tier price: $" + batchTier.Price);
|
|
358
|
+
* }
|
|
359
|
+
* }
|
|
288
360
|
*/
|
|
289
361
|
BatchTiers: Tier[];
|
|
290
362
|
|
|
291
363
|
/**
|
|
292
364
|
* Price per record (-1 if not valid)
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* if (Item.PricePerRecord > 0 && Item.NumberOfRecords > 0) {
|
|
368
|
+
* var recordTotal = Item.PricePerRecord * Item.NumberOfRecords;
|
|
369
|
+
* debug("Record pricing: " + Item.NumberOfRecords + " x $" + Item.PricePerRecord);
|
|
370
|
+
* return recordTotal;
|
|
371
|
+
* }
|
|
293
372
|
*/
|
|
294
373
|
PricePerRecord: number;
|
|
295
374
|
|
|
296
375
|
/**
|
|
297
376
|
* Array of attributes with Key, Value, IsRequired, Prompt, PriceAdjustment, etc.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* // Loop through all attributes and apply price adjustments
|
|
380
|
+
* var totalAdjustment = 0;
|
|
381
|
+
* for (var i = 0; i < Item.Attributes.length; i++) {
|
|
382
|
+
* var attr = Item.Attributes[i];
|
|
383
|
+
* debug("Attribute: " + attr.Key + " = " + attr.Value);
|
|
384
|
+
* totalAdjustment += attr.PriceAdjustment || 0;
|
|
385
|
+
* }
|
|
386
|
+
* return Item.Price + totalAdjustment;
|
|
298
387
|
*/
|
|
299
388
|
Attributes: Attribute[];
|
|
300
389
|
|
|
301
390
|
/**
|
|
302
391
|
* User email
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* // Apply corporate discount for company emails
|
|
395
|
+
* if (Item.Email.endsWith("@mycompany.com")) {
|
|
396
|
+
* debug("Corporate customer: " + Item.Email);
|
|
397
|
+
* return Item.Price * 0.85; // 15% corporate discount
|
|
398
|
+
* }
|
|
303
399
|
*/
|
|
304
400
|
Email: string;
|
|
305
401
|
|
|
306
402
|
/**
|
|
307
403
|
* Array of customer role system names
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* // Check for wholesale pricing
|
|
407
|
+
* if (Item.CustomerRoles.indexOf("Wholesale") >= 0) {
|
|
408
|
+
* debug("Wholesale customer detected");
|
|
409
|
+
* return Item.Price * 0.70; // 30% wholesale discount
|
|
410
|
+
* } else if (Item.CustomerRoles.indexOf("VIP") >= 0) {
|
|
411
|
+
* return Item.Price * 0.90; // 10% VIP discount
|
|
412
|
+
* }
|
|
308
413
|
*/
|
|
309
414
|
CustomerRoles: string[];
|
|
310
415
|
|
|
311
416
|
/**
|
|
312
417
|
* Department name of user
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* // Apply department-specific pricing
|
|
421
|
+
* if (Item.Department === "Marketing") {
|
|
422
|
+
* debug("Marketing department order");
|
|
423
|
+
* return Item.Price * 0.80; // 20% marketing discount
|
|
424
|
+
* } else if (Item.Department === "Sales") {
|
|
425
|
+
* return Item.Price * 0.75; // 25% sales discount
|
|
426
|
+
* }
|
|
313
427
|
*/
|
|
314
428
|
Department: string;
|
|
315
429
|
|
|
316
430
|
/**
|
|
317
431
|
* Array of other order items using the same custom pricing script
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* // Calculate total quantity across all cart items for volume discount
|
|
435
|
+
* var totalQty = Item.Quantity;
|
|
436
|
+
* for (var i = 0; i < Item.OtherOrderItems.length; i++) {
|
|
437
|
+
* totalQty += Item.OtherOrderItems[i].Quantity;
|
|
438
|
+
* }
|
|
439
|
+
* debug("Total quantity in cart: " + totalQty);
|
|
318
440
|
*/
|
|
319
441
|
OtherOrderItems: Item[];
|
|
320
442
|
|
|
321
443
|
/**
|
|
322
444
|
* Alias of OtherOrderItems
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* // Apply cart-wide discount if total exceeds threshold
|
|
448
|
+
* var cartTotal = 0;
|
|
449
|
+
* for (var i = 0; i < Item.CartItems.length; i++) {
|
|
450
|
+
* cartTotal += Item.CartItems[i].Price * Item.CartItems[i].Quantity;
|
|
451
|
+
* }
|
|
452
|
+
* if (cartTotal > 500) {
|
|
453
|
+
* debug("Cart total $" + cartTotal + " - applying 10% discount");
|
|
454
|
+
* return Item.Price * 0.90;
|
|
455
|
+
* }
|
|
323
456
|
*/
|
|
324
457
|
CartItems: Item[];
|
|
325
458
|
|
|
326
459
|
/**
|
|
327
460
|
* Index of this item in the other order item array (0 if not in array)
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* // Apply setup fee only to first item
|
|
464
|
+
* if (Item.OrderItemIndex === 0) {
|
|
465
|
+
* debug("First item - adding setup fee");
|
|
466
|
+
* return Item.Price + 15.00;
|
|
467
|
+
* }
|
|
328
468
|
*/
|
|
329
469
|
OrderItemIndex: number;
|
|
330
470
|
|
|
331
471
|
/**
|
|
332
472
|
* Index of this item in the other order item array (-1 if not in array)
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* if (Item.CartItemIndex >= 0) {
|
|
476
|
+
* debug("This is cart item #" + (Item.CartItemIndex + 1));
|
|
477
|
+
* }
|
|
333
478
|
*/
|
|
334
479
|
CartItemIndex: number;
|
|
335
480
|
|
|
336
481
|
/**
|
|
337
482
|
* Whether this item is in the other order item array
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* if (Item.IsInOtherOrderItems) {
|
|
486
|
+
* debug("Item is part of multi-item order");
|
|
487
|
+
* // Consider other items for bundle pricing
|
|
488
|
+
* }
|
|
338
489
|
*/
|
|
339
490
|
IsInOtherOrderItems: boolean;
|
|
340
491
|
|
|
341
492
|
/**
|
|
342
493
|
* Value of the currently used discount code
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* // Apply special discount for specific codes
|
|
497
|
+
* if (Item.DiscountCode === "SUMMER20") {
|
|
498
|
+
* debug("Summer sale discount applied");
|
|
499
|
+
* return Item.Price * 0.80; // 20% off
|
|
500
|
+
* } else if (Item.DiscountCode === "VIP50") {
|
|
501
|
+
* return Item.Price * 0.50; // 50% off
|
|
502
|
+
* }
|
|
343
503
|
*/
|
|
344
504
|
DiscountCode: string;
|
|
345
505
|
|
|
346
506
|
/**
|
|
347
507
|
* Array of versions with JobId, CustomName, and Quantity
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* // Calculate pricing across all versions
|
|
511
|
+
* if (Item.Versions.length > 0) {
|
|
512
|
+
* debug("Job has " + Item.Versions.length + " versions");
|
|
513
|
+
* for (var i = 0; i < Item.Versions.length; i++) {
|
|
514
|
+
* var ver = Item.Versions[i];
|
|
515
|
+
* debug("Version: " + ver.CustomName + ", Qty: " + ver.Quantity);
|
|
516
|
+
* }
|
|
517
|
+
* }
|
|
348
518
|
*/
|
|
349
519
|
Versions: ItemVersion[];
|
|
350
520
|
|
|
351
521
|
/**
|
|
352
522
|
* Number of versions
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* if (Item.NumberOfVersions > 1) {
|
|
526
|
+
* debug("Multi-version job with " + Item.NumberOfVersions + " versions");
|
|
527
|
+
* // Apply version discount
|
|
528
|
+
* return Item.Price * 0.95; // 5% multi-version discount
|
|
529
|
+
* }
|
|
353
530
|
*/
|
|
354
531
|
NumberOfVersions: number;
|
|
355
532
|
|
|
356
533
|
/**
|
|
357
534
|
* Whether this is a version of a job
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* if (Item.IsVersion) {
|
|
538
|
+
* debug("This item is a version of an existing job");
|
|
539
|
+
* // Use version-specific pricing logic
|
|
540
|
+
* }
|
|
358
541
|
*/
|
|
359
542
|
IsVersion: boolean;
|
|
360
543
|
|
|
361
544
|
/**
|
|
362
545
|
* Sum of all quantities of all versions
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* // Use total version quantity for tier pricing
|
|
549
|
+
* if (Item.VersionsSumQuantity > 0) {
|
|
550
|
+
* var tier = HelperMethods.FindTier(Item.VersionsSumQuantity, Item.PricingTiers);
|
|
551
|
+
* if (tier) {
|
|
552
|
+
* debug("Using combined version quantity: " + Item.VersionsSumQuantity);
|
|
553
|
+
* return tier.Price;
|
|
554
|
+
* }
|
|
555
|
+
* }
|
|
363
556
|
*/
|
|
364
557
|
VersionsSumQuantity: number;
|
|
365
558
|
|
package/v1/Output/Output.d.ts
CHANGED
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
* Output a debug message to the user interface.
|
|
16
16
|
* Debug messages are typically used during development and troubleshooting
|
|
17
17
|
* to provide detailed information about script execution and calculations.
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* @category Output Functions
|
|
19
20
|
* @param message - The debug message to display to the user
|
|
20
|
-
*
|
|
21
|
+
*
|
|
21
22
|
* @example
|
|
22
23
|
* debug("Calculating price for item: " + Item.ProductName);
|
|
23
24
|
* debug("Base price: $" + Item.Price + ", Quantity: " + Item.Quantity);
|
|
@@ -28,9 +29,10 @@ declare function debug(message: string): void;
|
|
|
28
29
|
* Output an alert message to the user interface.
|
|
29
30
|
* Alert messages are used to display important information that requires
|
|
30
31
|
* user attention, such as pricing changes or special offers.
|
|
31
|
-
*
|
|
32
|
+
*
|
|
33
|
+
* @category Output Functions
|
|
32
34
|
* @param message - The alert message to display to the user
|
|
33
|
-
*
|
|
35
|
+
*
|
|
34
36
|
* @example
|
|
35
37
|
* alert("Special pricing applied: 20% discount for bulk orders");
|
|
36
38
|
* alert("Price updated based on selected attributes");
|
|
@@ -41,9 +43,10 @@ declare function alert(message: string): void;
|
|
|
41
43
|
* Output a warning message to the user interface.
|
|
42
44
|
* Warning messages are used to notify users about potential issues
|
|
43
45
|
* or important considerations that may affect their pricing.
|
|
44
|
-
*
|
|
46
|
+
*
|
|
47
|
+
* @category Output Functions
|
|
45
48
|
* @param message - The warning message to display to the user
|
|
46
|
-
*
|
|
49
|
+
*
|
|
47
50
|
* @example
|
|
48
51
|
* warning("Large file detected - processing may take longer");
|
|
49
52
|
* warning("Some attributes may affect shipping costs");
|
|
@@ -54,9 +57,10 @@ declare function warning(message: string): void;
|
|
|
54
57
|
* Output an error message to the user interface.
|
|
55
58
|
* Error messages are used to inform users about calculation failures
|
|
56
59
|
* or other issues that prevent normal pricing execution.
|
|
57
|
-
*
|
|
60
|
+
*
|
|
61
|
+
* @category Output Functions
|
|
58
62
|
* @param message - The error message to display to the user
|
|
59
|
-
*
|
|
63
|
+
*
|
|
60
64
|
* @example
|
|
61
65
|
* error("Unable to calculate price - missing required attributes");
|
|
62
66
|
* error("File processing failed - please check file format");
|
|
@@ -67,9 +71,10 @@ declare function error(message: string): void;
|
|
|
67
71
|
* Output a message to the browser console/logs.
|
|
68
72
|
* Console messages are used for debugging purposes and are typically
|
|
69
73
|
* only visible to developers in the browser's developer tools.
|
|
70
|
-
*
|
|
74
|
+
*
|
|
75
|
+
* @category Output Functions
|
|
71
76
|
* @param message - The message to log to the console
|
|
72
|
-
*
|
|
77
|
+
*
|
|
73
78
|
* @example
|
|
74
79
|
* console("Script execution started");
|
|
75
80
|
* console("Final calculated price: $" + finalPrice);
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
* The session object available in pricing scripts.
|
|
14
14
|
* Represents session-level data and provides access to customer information
|
|
15
15
|
* and shopping cart items that are available during the current session.
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
17
|
* This object provides session-wide context for pricing calculations that
|
|
18
18
|
* may need to consider multiple items or customer session data.
|
|
19
|
+
*
|
|
20
|
+
* @category Global Objects
|
|
19
21
|
*/
|
|
20
22
|
declare interface Session {
|
|
21
23
|
/**
|