@infigo-official/types-for-pricing-script 1.0.0 → 1.0.1

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Type definitions for the Pricing Script scripting interface.
4
4
 
5
- Full documentation is available [here](https://infigo-official.github.io/types-for-pricing-script/).
5
+ Full documentation is available [here](https://infigo-official.github.io/types-for-pricing-scripts/).
6
6
 
7
7
  Use and install the package to get the best experience and IntelliSense support within our IDE.
8
8
  Choose dev dependencies if you are developing in Javascript or our code will not be reused in another project.
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@infigo-official/types-for-pricing-script",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Type definitions for Pricing Script Scripting",
5
5
  "types": "v1/index.d.ts",
6
6
  "devDependencies": {
7
- "typedoc": "^0.26.6",
8
- "typescript": "^5.5.4"
7
+ "typedoc": "^0.24.8",
8
+ "typescript": "^4.9.5"
9
9
  },
10
10
  "scripts": {
11
- "docs": "npx typedoc"
11
+ "docs": "npx typedoc",
12
+ "start": "npx http-server docs -p 3000 -o"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",
15
- "url": "git+https://github.com/Infigo-Official/types-for-pricing-script.git"
16
+ "url": "git+https://github.com/Infigo-Official/types-for-pricing-scripts.git"
16
17
  },
17
18
  "keywords": [
18
19
  "typedefinitions",
@@ -22,9 +23,9 @@
22
23
  "author": "Infigo",
23
24
  "license": "MIT",
24
25
  "bugs": {
25
- "url": "https://github.com/Infigo-Official/types-for-pricing-script/issues"
26
+ "url": "https://github.com/Infigo-Official/types-for-pricing-scripts/issues"
26
27
  },
27
- "homepage": "https://github.com/Infigo-Official/types-for-pricing-script#readme",
28
+ "homepage": "https://github.com/Infigo-Official/types-for-pricing-scripts#readme",
28
29
  "files": [
29
30
  "v1",
30
31
  "package.json",
@@ -7,7 +7,7 @@
7
7
  * - Custom configuration data
8
8
  * - System-wide settings
9
9
  *
10
- * @module System / Configuration
10
+ * @module Configuration
11
11
  */
12
12
 
13
13
  /**
@@ -45,4 +45,6 @@ declare interface ConfigurationInterface {
45
45
  * var scriptConfig = Configuration.ScriptConfig;
46
46
  * var customSetting = scriptConfig.customParameter;
47
47
  */
48
- declare const Configuration: ConfigurationInterface;
48
+ declare const Configuration: ConfigurationInterface;
49
+
50
+
@@ -357,6 +357,47 @@ declare interface Item {
357
357
  }
358
358
 
359
359
  /**
360
- * Global Item object
360
+ * Global Item object available in pricing scripts
361
+ * This constant provides access to all item-related data and functionality,
362
+ * allowing scripts to retrieve product information, pricing data, attributes,
363
+ * and perform various operations on the current item being priced.
364
+ *
365
+ * The Item object contains comprehensive information about the product variant
366
+ * including pricing details, attributes, customer information, file attachments,
367
+ * and methods for data manipulation and file handling.
368
+ *
369
+ * @example
370
+ * // Access basic product information
371
+ * var productName = Item.ProductName;
372
+ * var basePrice = Item.Price;
373
+ * var quantity = Item.Quantity;
374
+ *
375
+ * // Work with attributes
376
+ * for (var i = 0; i < Item.Attributes.length; i++) {
377
+ * var attr = Item.Attributes[i];
378
+ * debug("Attribute: " + attr.Key + " = " + attr.Value);
379
+ * }
380
+ *
381
+ * // Get file information
382
+ * var fileInfo = Item.getFileInfo("fileAttributeId", true);
383
+ * if (fileInfo.NumberOfPages > 0) {
384
+ * debug("File has " + fileInfo.NumberOfPages + " pages");
385
+ * }
386
+ *
387
+ * // Access customer information
388
+ * if (Item.CustomerRoles.indexOf("VIP") >= 0) {
389
+ * // Apply VIP pricing logic
390
+ * }
391
+ *
392
+ * // Work with pricing tiers
393
+ * var tier = HelperMethods.FindTier(Item.Quantity, Item.PricingTiers, Item.CustomerRoles);
394
+ * if (tier) {
395
+ * debug("Using tier: " + tier.Quantity + " @ $" + tier.Price);
396
+ * }
397
+ *
398
+ * // Calculate final price
399
+ * var finalPrice = Item.Price;
400
+ * finalPrice += HelperMethods.GetAttributePriceAdjustment(Item.Quantity, Item.CustomerRoles);
401
+ * return finalPrice;
361
402
  */
362
403
  declare const Item: Item;
@@ -0,0 +1,261 @@
1
+ /**
2
+ * This module provides utility functions for common pricing calculations and data manipulation tasks.
3
+ * Helper methods make it easier to write complex pricing logic by providing pre-built functionality
4
+ * for common operations including:
5
+ * - Tier-based pricing calculations
6
+ * - Attribute price adjustments
7
+ * - Price interpolation between tiers
8
+ * - CSV data parsing and manipulation
9
+ * - Object manipulation and debugging utilities
10
+ *
11
+ * @module Helper / HelperMethods
12
+ */
13
+
14
+ /**
15
+ * CSV parsing options for configuring CSV parsing behavior
16
+ */
17
+ declare interface CsvOptions {
18
+ /**
19
+ * Delimiter character used to separate fields in CSV (default: ",")
20
+ */
21
+ delimiterChar?: string;
22
+
23
+ /**
24
+ * Quote character used to enclose fields containing delimiters (default: '"')
25
+ */
26
+ quoteChar?: string;
27
+
28
+ /**
29
+ * Whether to disable automatic number conversion (default: false)
30
+ * When true, all values remain as strings
31
+ */
32
+ disableNumberConverstion?: boolean;
33
+ }
34
+
35
+ /**
36
+ * CSV replacer function type for custom value transformation during stringify operations
37
+ * @param row - Row index (0-based)
38
+ * @param col - Column index (0-based)
39
+ * @param value - Current value to transform
40
+ * @returns Transformed value
41
+ */
42
+ declare type CsvReplacer = (row: number, col: number, value: any) => any;
43
+
44
+ /**
45
+ * CSV stringify options for configuring CSV output format
46
+ */
47
+ declare interface CsvStringifyOptions {
48
+ /**
49
+ * Delimiter character used to separate fields in output CSV (default: ",")
50
+ */
51
+ delimiterChar?: string;
52
+
53
+ /**
54
+ * Quote character used to enclose fields containing delimiters (default: '"')
55
+ */
56
+ quoteChar?: string;
57
+
58
+ /**
59
+ * Replacer function for custom value transformation during stringify
60
+ */
61
+ replacer?: CsvReplacer;
62
+ }
63
+
64
+ /**
65
+ * CSV helper methods for parsing and stringifying CSV data
66
+ * Provides utilities for working with CSV files and data in pricing scripts
67
+ */
68
+ declare interface CsvHelper {
69
+ /**
70
+ * Parse CSV string into array of arrays
71
+ * Converts CSV text data into a structured format for processing in pricing scripts
72
+ *
73
+ * @param csv - CSV string to parse
74
+ * @param options - Parsing options to configure delimiter, quote character, etc.
75
+ * @param disableNumberConversion - Whether to disable automatic number conversion
76
+ * @returns Array of arrays representing the CSV data, where each inner array is a row
77
+ *
78
+ * @example
79
+ * var csvData = HelperMethods.CSV.parse("1,Product A,10.99\n2,Product B,15.50");
80
+ * // Result: [["1", "Product A", "10.99"], ["2", "Product B", "15.50"]]
81
+ */
82
+ parse(csv: string, options?: CsvOptions, disableNumberConversion?: boolean): any[][];
83
+
84
+ /**
85
+ * Convert array of arrays to CSV string
86
+ * Converts structured data back to CSV format for output or file generation
87
+ *
88
+ * @param table - Array of arrays to convert, where each inner array is a row
89
+ * @param options - Stringify options to configure output format
90
+ * @returns CSV string representation of the data
91
+ *
92
+ * @example
93
+ * var data = [["1", "Product A", "10.99"], ["2", "Product B", "15.50"]];
94
+ * var csvString = HelperMethods.CSV.stringify(data);
95
+ * // Result: "1,Product A,10.99\n2,Product B,15.50"
96
+ */
97
+ stringify(table: any[][], options?: CsvStringifyOptions): string;
98
+ }
99
+
100
+ /**
101
+ * Helper methods available in pricing scripts for common calculations and data manipulation
102
+ * These utilities extend the capabilities of pricing scripts and help create more flexible
103
+ * and maintainable pricing logic.
104
+ */
105
+ declare interface HelperMethods {
106
+ /**
107
+ * Find appropriate pricing tier based on quantity and customer roles
108
+ * Searches through tier arrays to find the best matching tier for the given quantity
109
+ * and customer roles, supporting both regular pricing tiers and batch tiers
110
+ *
111
+ * @param quantity - The quantity which you would like the price to be worked out based on
112
+ * @param tiers - An array of object literals [{Quantity: n, Price: n, CustomerRole?: string}]
113
+ * @param roles - Array of string that contains customer roles, falls back to Customer.Roles if not supplied
114
+ * @returns Tier object or null if no matching tier found
115
+ *
116
+ * @example
117
+ * var tiers = [{Quantity: 1, Price: 5}, {Quantity: 50, Price: 17}, {Quantity: 250, Price: 60}];
118
+ * var tier = HelperMethods.FindTier(100, tiers, ["SuperAdmin", "Admin"]);
119
+ * // Returns the tier with Quantity: 50, Price: 17
120
+ */
121
+ FindTier(quantity: number, tiers: Tier[], roles?: string[]): Tier | null;
122
+
123
+ /**
124
+ * Get attribute price adjustments including tier-based adjustments
125
+ * Calculates the total price adjustment for all selected attributes, taking into account
126
+ * tier-based pricing adjustments that can vary based on quantity or customer roles
127
+ *
128
+ * @param quantity - The quantity which you would like the price to be worked out based on
129
+ * @param roles - Array of string that contains customer roles, falls back to Customer.Roles if not supplied
130
+ * @returns Total price adjustment including all attribute and tier adjustments
131
+ *
132
+ * @example
133
+ * var attributeAdjustment = HelperMethods.GetAttributePriceAdjustment(43, ["SuperAdmin", "Admin"]);
134
+ * // Returns the total price adjustment for quantity 43 with specified customer roles
135
+ */
136
+ GetAttributePriceAdjustment(quantity: number, roles?: string[]): number;
137
+
138
+ /**
139
+ * Interpolate prices between tier boundaries for smooth pricing transitions
140
+ * Calculates a price that falls between tier boundaries based on the specified quantity,
141
+ * providing smooth pricing curves rather than step-based pricing
142
+ *
143
+ * @param quantity - The quantity which you would like the price to be worked out based on
144
+ * @param tiers - An array of object literals [{Quantity: n, Price: n}] for interpolation
145
+ * @returns Interpolated price based on quantity position within the specified tiers
146
+ *
147
+ * @example
148
+ * var interpolationTiers = [
149
+ * {Quantity: 1, Price: 5}, {Quantity: 50, Price: 17},
150
+ * {Quantity: 250, Price: 60}, {Quantity: 500, Price: 100},
151
+ * {Quantity: 1000, Price: 200}
152
+ * ];
153
+ * var tierPrice = HelperMethods.InterpolatePrice(Item.Quantity, interpolationTiers);
154
+ * // Returns interpolated price based on Item.Quantity position within tiers
155
+ */
156
+ InterpolatePrice(quantity: number, tiers: Tier[]): number;
157
+
158
+ /**
159
+ * Log object properties for debugging complex pricing scenarios
160
+ * Outputs all properties of an object to the console for debugging purposes,
161
+ * useful for examining complex data structures during script development
162
+ *
163
+ * @param data - Object to log all properties from
164
+ *
165
+ * @example
166
+ * HelperMethods.LogObject(Item);
167
+ * // Logs all Item properties to console for debugging
168
+ */
169
+ LogObject(data: any): void;
170
+
171
+ /**
172
+ * Check if arrays contain specific values for conditional logic
173
+ * Utility function for checking array membership in conditional pricing logic
174
+ *
175
+ * @param array - Array to check for the specified value
176
+ * @param value - Value to search for in the array
177
+ * @returns Whether the value is found in the array
178
+ *
179
+ * @example
180
+ * if (HelperMethods.Contains(Item.CustomerRoles, "VIP")) {
181
+ * // Apply VIP pricing logic
182
+ * }
183
+ */
184
+ Contains(array: any[], value: any): boolean;
185
+
186
+ /**
187
+ * Type checking utility for robust script development
188
+ * Determines if an item is a plain object (not null, not array, not primitive)
189
+ *
190
+ * @param item - Item to check if it's an object
191
+ * @returns Whether the item is an object
192
+ *
193
+ * @example
194
+ * if (HelperMethods.IsObject(config)) {
195
+ * // Process configuration object
196
+ * }
197
+ */
198
+ IsObject(item: any): boolean;
199
+
200
+ /**
201
+ * Type checking utility for robust script development
202
+ * Determines if an item is an array
203
+ *
204
+ * @param item - Item to check if it's an array
205
+ * @returns Whether the item is an array
206
+ *
207
+ * @example
208
+ * if (HelperMethods.IsArray(Item.Attributes)) {
209
+ * // Process attributes array
210
+ * }
211
+ */
212
+ IsArray(item: any): boolean;
213
+
214
+ /**
215
+ * Deep merge objects with conflict resolution for combining pricing data
216
+ * Merges source object properties into target object, handling nested objects
217
+ * and providing a way to combine configuration data from multiple sources
218
+ *
219
+ * @param target - Target object to merge properties into
220
+ * @param source - Source object to merge properties from
221
+ *
222
+ * @example
223
+ * var baseConfig = {markup: 20, shipping: 5};
224
+ * var overrideConfig = {markup: 25};
225
+ * HelperMethods.MergeObject(baseConfig, overrideConfig);
226
+ * // baseConfig now has {markup: 25, shipping: 5}
227
+ */
228
+ MergeObject(target: any, source: any): void;
229
+
230
+ /**
231
+ * CSV parsing and stringifying utilities for data-driven pricing
232
+ * Provides comprehensive CSV handling capabilities for working with external data
233
+ * files, configuration data, and bulk pricing information
234
+ *
235
+ * @example
236
+ * // Parse CSV file content
237
+ * var csvContent = HelperMethods.CSV.parse(fileContent);
238
+ *
239
+ * // Generate CSV output
240
+ * var outputData = [["Product", "Price"], ["Item A", "10.99"]];
241
+ * var csvOutput = HelperMethods.CSV.stringify(outputData);
242
+ */
243
+ CSV: CsvHelper;
244
+ }
245
+
246
+ /**
247
+ * Global HelperMethods object available in pricing scripts
248
+ * This constant provides access to all helper methods and utilities,
249
+ * allowing scripts to use advanced functionality for complex pricing calculations
250
+ *
251
+ * @example
252
+ * // Use interpolation for tier-based pricing
253
+ * var tierPrice = HelperMethods.InterpolatePrice(Item.Quantity, pricingTiers);
254
+ *
255
+ * // Get attribute adjustments
256
+ * var adjustments = HelperMethods.GetAttributePriceAdjustment(Item.Quantity, Item.CustomerRoles);
257
+ *
258
+ * // Parse CSV data
259
+ * var data = HelperMethods.CSV.parse(csvString);
260
+ */
261
+ declare const HelperMethods: HelperMethods;
@@ -8,7 +8,7 @@
8
8
  * - Error messages for calculation failures
9
9
  * - Console logging for debugging purposes
10
10
  *
11
- * @module System / Output
11
+ * @module Output
12
12
  */
13
13
 
14
14
  /**
@@ -68,14 +68,14 @@ declare function error(message: string): void;
68
68
  * Console messages are used for debugging purposes and are typically
69
69
  * only visible to developers in the browser's developer tools.
70
70
  *
71
+ * Note: In the actual Infigo pricing script environment, this function is called `console()`.
72
+ * The TypeScript declaration uses `consoleLog()` to avoid conflicts with the built-in console object.
73
+ *
71
74
  * @param message - The message to log to the console
72
75
  *
73
76
  * @example
74
- * consoleLog("Script execution started");
75
- * consoleLog("Final calculated price: $" + finalPrice);
77
+ * // In actual pricing scripts, use: console("Script execution started");
78
+ * console("Script execution started");
79
+ * console("Final calculated price: $" + finalPrice);
76
80
  */
77
81
  declare function consoleLog(message: string): void;
78
-
79
-
80
-
81
-
package/v1/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- /// <reference path="Item/Item.d.ts" />
2
- /// <reference path="Item/Attribute.d.ts" />
3
- /// <reference path="Item/Tier.d.ts" />
4
- /// <reference path="Item/Version.d.ts" />
1
+ /// <reference path="Core/Item.d.ts" />
2
+ /// <reference path="Core/Attribute.d.ts" />
3
+ /// <reference path="Core/Tier.d.ts" />
4
+ /// <reference path="Core/Version.d.ts" />
5
5
  /// <reference path="File/FileInfo.d.ts" />
6
- /// <reference path="System/Configuration.d.ts" />
7
- /// <reference path="System/Output.d.ts" />
8
- /// <reference path="Helper/HelperMethods.d.ts" />
6
+ /// <reference path="Configuration/Configuration.d.ts" />
7
+ /// <reference path="Output/Output.d.ts" />
8
+ /// <reference path="Helpers/index.d.ts" />
@@ -1,141 +0,0 @@
1
- /**
2
- * CSV parsing options
3
- */
4
- declare interface CsvOptions {
5
- /**
6
- * Delimiter character (default: ",")
7
- */
8
- delimiterChar?: string;
9
-
10
- /**
11
- * Quote character (default: '"')
12
- */
13
- quoteChar?: string;
14
-
15
- /**
16
- * Whether to disable number conversion (default: false)
17
- */
18
- disableNumberConverstion?: boolean;
19
- }
20
-
21
- /**
22
- * CSV replacer function for stringify
23
- */
24
- declare type CsvReplacer = (row: number, col: number, value: any) => any;
25
-
26
- /**
27
- * CSV stringify options
28
- */
29
- declare interface CsvStringifyOptions {
30
- /**
31
- * Delimiter character (default: ",")
32
- */
33
- delimiterChar?: string;
34
-
35
- /**
36
- * Quote character (default: '"')
37
- */
38
- quoteChar?: string;
39
-
40
- /**
41
- * Replacer function for custom value transformation
42
- */
43
- replacer?: CsvReplacer;
44
- }
45
-
46
- /**
47
- * CSV helper methods
48
- */
49
- declare interface CsvHelper {
50
- /**
51
- * Parse CSV string into array of arrays
52
- * @param csv - CSV string to parse
53
- * @param options - Parsing options
54
- * @param disableNumberConversion - Whether to disable number conversion
55
- * @returns Array of arrays representing the CSV data
56
- */
57
- parse(csv: string, options?: CsvOptions, disableNumberConversion?: boolean): any[][];
58
-
59
- /**
60
- * Convert array of arrays to CSV string
61
- * @param table - Array of arrays to convert
62
- * @param options - Stringify options
63
- * @returns CSV string
64
- */
65
- stringify(table: any[][], options?: CsvStringifyOptions): string;
66
- }
67
-
68
- /**
69
- * Helper methods available in pricing scripts
70
- */
71
- declare interface HelperMethods {
72
- /**
73
- * Find the appropriate tier based on quantity and customer roles
74
- * @param quantity - The quantity to find tier for
75
- * @param tiers - Array of tier objects
76
- * @param roles - Array of customer role system names
77
- * @returns Tier object or null if no tier found
78
- */
79
- FindTier(quantity: number, tiers: Tier[], roles?: string[]): Tier | null;
80
-
81
- /**
82
- * Get attribute price adjustments including tier price adjustments
83
- * @param quantity - The quantity to get adjustments for
84
- * @param roles - Array of customer role system names
85
- * @returns Total price adjustment
86
- */
87
- GetAttributePriceAdjustment(quantity: number, roles?: string[]): number;
88
-
89
- /**
90
- * Interpolate price based on quantity and tiers
91
- * @param quantity - The quantity to interpolate price for
92
- * @param tiers - Array of tier objects
93
- * @returns Interpolated price
94
- */
95
- InterpolatePrice(quantity: number, tiers: Tier[]): number;
96
-
97
- /**
98
- * Log all properties of an object to console
99
- * @param data - Object to log
100
- */
101
- LogObject(data: any): void;
102
-
103
- /**
104
- * Check if an array contains a specific value
105
- * @param array - Array to check
106
- * @param value - Value to search for
107
- * @returns Whether the value is found
108
- */
109
- Contains(array: any[], value: any): boolean;
110
-
111
- /**
112
- * Check if an item is an object
113
- * @param item - Item to check
114
- * @returns Whether the item is an object
115
- */
116
- IsObject(item: any): boolean;
117
-
118
- /**
119
- * Check if an item is an array
120
- * @param item - Item to check
121
- * @returns Whether the item is an array
122
- */
123
- IsArray(item: any): boolean;
124
-
125
- /**
126
- * Merge source object into target object
127
- * @param target - Target object to merge into
128
- * @param source - Source object to merge from
129
- */
130
- MergeObject(target: any, source: any): void;
131
-
132
- /**
133
- * CSV parsing and stringifying utilities
134
- */
135
- CSV: CsvHelper;
136
- }
137
-
138
- /**
139
- * Global HelperMethods object
140
- */
141
- declare const HelperMethods: HelperMethods;
File without changes
File without changes
File without changes