pakdatakit 2.3.0 → 2.5.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.
Files changed (96) hide show
  1. package/DATA.md +212 -3
  2. package/LICENSE +1 -1
  3. package/NOTICE +14 -0
  4. package/README.md +304 -5
  5. package/dist/address.cjs +5 -4
  6. package/dist/address.js +3 -2
  7. package/dist/bills.cjs +19 -0
  8. package/dist/bills.d.cts +63 -0
  9. package/dist/bills.d.ts +63 -0
  10. package/dist/bills.js +2 -0
  11. package/dist/{chunk-OKMBYX3F.cjs → chunk-33GOK7EE.cjs} +2 -910
  12. package/dist/chunk-34U2ZMHR.js +194 -0
  13. package/dist/chunk-4GSBHJX6.js +165 -0
  14. package/dist/chunk-5DDHO5Z7.cjs +565 -0
  15. package/dist/chunk-5EY5DQS7.js +51 -0
  16. package/dist/chunk-5RGX4DWF.js +559 -0
  17. package/dist/chunk-5UCRHVI4.cjs +302 -0
  18. package/dist/{chunk-TQP2T33V.js → chunk-B7DOQ5QF.js} +2 -1
  19. package/dist/chunk-CF6AMRBU.cjs +198 -0
  20. package/dist/chunk-CZOZB4K3.js +61 -0
  21. package/dist/chunk-E2XU6NOW.js +909 -0
  22. package/dist/chunk-E6GWBOKV.cjs +911 -0
  23. package/dist/chunk-EA3SIHYT.js +313 -0
  24. package/dist/{chunk-YTSMFGTW.js → chunk-IDTRFOQW.js} +8 -3
  25. package/dist/chunk-OTI7HY55.js +297 -0
  26. package/dist/{chunk-J5ARB4TE.cjs → chunk-QFPEFD67.cjs} +5 -4
  27. package/dist/chunk-SF4ECUZ6.cjs +56 -0
  28. package/dist/chunk-UYFTXD4P.js +168 -0
  29. package/dist/{chunk-TBTWZC74.cjs → chunk-XCFZKCV2.cjs} +8 -3
  30. package/dist/{chunk-N4S22XX3.js → chunk-XOTCIXY6.js} +2 -909
  31. package/dist/chunk-XVEG53NN.cjs +322 -0
  32. package/dist/chunk-YDUXIENX.cjs +172 -0
  33. package/dist/chunk-YPAWNWFD.cjs +168 -0
  34. package/dist/chunk-YQFI7W3I.cjs +65 -0
  35. package/dist/class-validator.cjs +16 -8
  36. package/dist/class-validator.d.cts +7 -1
  37. package/dist/class-validator.d.ts +7 -1
  38. package/dist/class-validator.js +15 -8
  39. package/dist/cli.js +1 -1
  40. package/dist/courier.cjs +16 -0
  41. package/dist/courier.d.cts +51 -0
  42. package/dist/courier.d.ts +51 -0
  43. package/dist/courier.js +3 -0
  44. package/dist/fbr-invoice.cjs +25 -0
  45. package/dist/fbr-invoice.d.cts +170 -0
  46. package/dist/fbr-invoice.d.ts +170 -0
  47. package/dist/fbr-invoice.js +4 -0
  48. package/dist/geo.cjs +11 -10
  49. package/dist/geo.js +2 -1
  50. package/dist/incometax.cjs +27 -0
  51. package/dist/incometax.d.cts +91 -0
  52. package/dist/incometax.d.ts +91 -0
  53. package/dist/incometax.js +2 -0
  54. package/dist/index.cjs +227 -123
  55. package/dist/index.d.cts +8 -2
  56. package/dist/index.d.ts +8 -2
  57. package/dist/index.js +21 -13
  58. package/dist/input.cjs +8 -8
  59. package/dist/input.js +2 -2
  60. package/dist/joi.cjs +14 -8
  61. package/dist/joi.d.cts +1 -0
  62. package/dist/joi.d.ts +1 -0
  63. package/dist/joi.js +13 -7
  64. package/dist/quality.cjs +25 -0
  65. package/dist/quality.d.cts +62 -0
  66. package/dist/quality.d.ts +62 -0
  67. package/dist/quality.js +8 -0
  68. package/dist/salestax.cjs +20 -0
  69. package/dist/salestax.d.cts +106 -0
  70. package/dist/salestax.d.ts +106 -0
  71. package/dist/salestax.js +3 -0
  72. package/dist/superstruct.cjs +14 -8
  73. package/dist/superstruct.d.cts +1 -0
  74. package/dist/superstruct.d.ts +1 -0
  75. package/dist/superstruct.js +13 -7
  76. package/dist/text.cjs +21 -5
  77. package/dist/text.d.cts +90 -1
  78. package/dist/text.d.ts +90 -1
  79. package/dist/text.js +1 -1
  80. package/dist/valibot.cjs +14 -8
  81. package/dist/valibot.d.cts +1 -0
  82. package/dist/valibot.d.ts +1 -0
  83. package/dist/valibot.js +13 -7
  84. package/dist/yup.cjs +14 -8
  85. package/dist/yup.d.cts +1 -0
  86. package/dist/yup.d.ts +1 -0
  87. package/dist/yup.js +13 -7
  88. package/dist/zod.cjs +14 -8
  89. package/dist/zod.d.cts +1 -0
  90. package/dist/zod.d.ts +1 -0
  91. package/dist/zod.js +13 -7
  92. package/package.json +68 -5
  93. package/dist/chunk-JKE4AMSZ.js +0 -47
  94. package/dist/chunk-KEHCTYLO.cjs +0 -52
  95. package/dist/{chunk-A3HBEBXY.js → chunk-7DY26QPN.js} +1 -1
  96. package/dist/{chunk-FRBPAGEJ.cjs → chunk-TVL6RDAU.cjs} +1 -1
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ var chunkVPBMIYO2_cjs = require('./chunk-VPBMIYO2.cjs');
4
+
5
+ // src/bills.ts
6
+ var SEPARATORS = /[\s\-‐‑‒–—./]/g;
7
+ function parseElectricityRef(input) {
8
+ if (typeof input !== "string") return null;
9
+ let text = chunkVPBMIYO2_cjs.toAsciiDigits(input).replace(SEPARATORS, "").toUpperCase();
10
+ let urbanRural = null;
11
+ const letter = /^(\d{14})([UR])$/.exec(text);
12
+ if (letter) {
13
+ text = letter[1];
14
+ urbanRural = letter[2];
15
+ }
16
+ if (!/^\d+$/.test(text)) return null;
17
+ if (text.length === 14) {
18
+ const formatted = `${text.slice(0, 2)} ${text.slice(2, 7)} ${text.slice(7)}`;
19
+ return {
20
+ type: "reference",
21
+ digits: text,
22
+ formatted: urbanRural ? `${formatted} ${urbanRural}` : formatted,
23
+ urbanRural,
24
+ disco: null
25
+ };
26
+ }
27
+ if (urbanRural !== null) return null;
28
+ if (text.length === 13 && text.startsWith("04000")) {
29
+ return {
30
+ type: "k-electric",
31
+ digits: text,
32
+ formatted: text,
33
+ urbanRural: null,
34
+ disco: "K-Electric"
35
+ };
36
+ }
37
+ if (text.length === 10 || text.length === 11) {
38
+ return {
39
+ type: "customer-id",
40
+ digits: text,
41
+ formatted: text,
42
+ urbanRural: null,
43
+ disco: null
44
+ };
45
+ }
46
+ return null;
47
+ }
48
+ function validateElectricityRef(input) {
49
+ return parseElectricityRef(input) !== null;
50
+ }
51
+ var GAS_DIGITS = {
52
+ SNGPL: 11,
53
+ SSGC: 10
54
+ };
55
+ function validateGasConsumerNumber(input, company) {
56
+ if (typeof input !== "string" || typeof company !== "string") return false;
57
+ const digits = GAS_DIGITS[company.toUpperCase()];
58
+ if (digits === void 0) return false;
59
+ const text = chunkVPBMIYO2_cjs.toAsciiDigits(input).replace(SEPARATORS, "");
60
+ return text.length === digits && /^\d+$/.test(text);
61
+ }
62
+
63
+ exports.parseElectricityRef = parseElectricityRef;
64
+ exports.validateElectricityRef = validateElectricityRef;
65
+ exports.validateGasConsumerNumber = validateGasConsumerNumber;
@@ -1,20 +1,25 @@
1
1
  'use strict';
2
2
 
3
- var chunkTBTWZC74_cjs = require('./chunk-TBTWZC74.cjs');
4
- require('./chunk-SQIHFEXI.cjs');
5
- require('./chunk-AUQFA7EE.cjs');
6
- require('./chunk-7E7L3NYS.cjs');
3
+ var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
7
4
  require('./chunk-ESKXG7Y6.cjs');
5
+ require('./chunk-YDUXIENX.cjs');
6
+ require('./chunk-H6M6L26S.cjs');
7
+ require('./chunk-SQIHFEXI.cjs');
8
+ require('./chunk-DHOP7LQX.cjs');
8
9
  require('./chunk-MTS6SVNP.cjs');
10
+ require('./chunk-AUQFA7EE.cjs');
9
11
  require('./chunk-YTLE5K7G.cjs');
10
- require('./chunk-H6M6L26S.cjs');
12
+ require('./chunk-7E7L3NYS.cjs');
13
+ require('./chunk-QFPEFD67.cjs');
14
+ require('./chunk-I7UUPD3G.cjs');
11
15
  require('./chunk-HTCSHHOR.cjs');
12
- require('./chunk-DHOP7LQX.cjs');
16
+ require('./chunk-33GOK7EE.cjs');
17
+ require('./chunk-E6GWBOKV.cjs');
13
18
  require('./chunk-VPBMIYO2.cjs');
14
19
  var classValidator = require('class-validator');
15
20
 
16
21
  function decorator(name) {
17
- const rule = chunkTBTWZC74_cjs.RULES[name];
22
+ const rule = chunkXCFZKCV2_cjs.RULES[name];
18
23
  return (options = {}) => (target, propertyName) => {
19
24
  classValidator.registerDecorator({
20
25
  name: `pk-${name}`,
@@ -35,7 +40,8 @@ var pk = {
35
40
  strn: decorator("strn"),
36
41
  landline: decorator("landline"),
37
42
  passport: decorator("passport"),
38
- vehiclePlate: decorator("vehiclePlate")
43
+ vehiclePlate: decorator("vehiclePlate"),
44
+ codPhone: decorator("codPhone")
39
45
  };
40
46
  var IsCNIC = pk.cnic;
41
47
  var IsPakPhone = pk.phone;
@@ -45,8 +51,10 @@ var IsSTRN = pk.strn;
45
51
  var IsPakLandline = pk.landline;
46
52
  var IsPakPassport = pk.passport;
47
53
  var IsVehiclePlate = pk.vehiclePlate;
54
+ var IsCodPhone = pk.codPhone;
48
55
 
49
56
  exports.IsCNIC = IsCNIC;
57
+ exports.IsCodPhone = IsCodPhone;
50
58
  exports.IsNTN = IsNTN;
51
59
  exports.IsPakIBAN = IsPakIBAN;
52
60
  exports.IsPakLandline = IsPakLandline;
@@ -32,6 +32,7 @@ declare const pk: {
32
32
  landline: (options?: DecoratorOptions) => PropertyDecorator;
33
33
  passport: (options?: DecoratorOptions) => PropertyDecorator;
34
34
  vehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
35
+ codPhone: (options?: DecoratorOptions) => PropertyDecorator;
35
36
  };
36
37
  /** Validates a CNIC. See {@link pk}. */
37
38
  declare const IsCNIC: (options?: DecoratorOptions) => PropertyDecorator;
@@ -52,6 +53,11 @@ declare const IsPakLandline: (options?: DecoratorOptions) => PropertyDecorator;
52
53
  declare const IsPakPassport: (options?: DecoratorOptions) => PropertyDecorator;
53
54
  /** Validates the format of a vehicle registration number. See {@link pk}. */
54
55
  declare const IsVehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
56
+ /**
57
+ * Validates a mobile number a courier can call: valid, and with no
58
+ * `phoneRiskSignals` flag. See {@link pk}.
59
+ */
60
+ declare const IsCodPhone: (options?: DecoratorOptions) => PropertyDecorator;
55
61
 
56
- export { IsCNIC, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
62
+ export { IsCNIC, IsCodPhone, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
57
63
  export type { DecoratorOptions };
@@ -32,6 +32,7 @@ declare const pk: {
32
32
  landline: (options?: DecoratorOptions) => PropertyDecorator;
33
33
  passport: (options?: DecoratorOptions) => PropertyDecorator;
34
34
  vehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
35
+ codPhone: (options?: DecoratorOptions) => PropertyDecorator;
35
36
  };
36
37
  /** Validates a CNIC. See {@link pk}. */
37
38
  declare const IsCNIC: (options?: DecoratorOptions) => PropertyDecorator;
@@ -52,6 +53,11 @@ declare const IsPakLandline: (options?: DecoratorOptions) => PropertyDecorator;
52
53
  declare const IsPakPassport: (options?: DecoratorOptions) => PropertyDecorator;
53
54
  /** Validates the format of a vehicle registration number. See {@link pk}. */
54
55
  declare const IsVehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
56
+ /**
57
+ * Validates a mobile number a courier can call: valid, and with no
58
+ * `phoneRiskSignals` flag. See {@link pk}.
59
+ */
60
+ declare const IsCodPhone: (options?: DecoratorOptions) => PropertyDecorator;
55
61
 
56
- export { IsCNIC, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
62
+ export { IsCNIC, IsCodPhone, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
57
63
  export type { DecoratorOptions };
@@ -1,13 +1,18 @@
1
- import { RULES } from './chunk-YTSMFGTW.js';
2
- import './chunk-RZQJAZKC.js';
3
- import './chunk-LQHM3ADX.js';
4
- import './chunk-E6HSKRAE.js';
1
+ import { RULES } from './chunk-IDTRFOQW.js';
5
2
  import './chunk-S274QFFB.js';
3
+ import './chunk-UYFTXD4P.js';
4
+ import './chunk-CEPNSHIC.js';
5
+ import './chunk-RZQJAZKC.js';
6
+ import './chunk-IBZPJS4H.js';
6
7
  import './chunk-V2XE3NCG.js';
8
+ import './chunk-LQHM3ADX.js';
7
9
  import './chunk-P7LVE2TF.js';
8
- import './chunk-CEPNSHIC.js';
10
+ import './chunk-E6HSKRAE.js';
11
+ import './chunk-B7DOQ5QF.js';
12
+ import './chunk-33QMFE2Z.js';
9
13
  import './chunk-EEVNLTB4.js';
10
- import './chunk-IBZPJS4H.js';
14
+ import './chunk-XOTCIXY6.js';
15
+ import './chunk-E2XU6NOW.js';
11
16
  import './chunk-ENQ7O7VW.js';
12
17
  import { registerDecorator } from 'class-validator';
13
18
 
@@ -33,7 +38,8 @@ var pk = {
33
38
  strn: decorator("strn"),
34
39
  landline: decorator("landline"),
35
40
  passport: decorator("passport"),
36
- vehiclePlate: decorator("vehiclePlate")
41
+ vehiclePlate: decorator("vehiclePlate"),
42
+ codPhone: decorator("codPhone")
37
43
  };
38
44
  var IsCNIC = pk.cnic;
39
45
  var IsPakPhone = pk.phone;
@@ -43,5 +49,6 @@ var IsSTRN = pk.strn;
43
49
  var IsPakLandline = pk.landline;
44
50
  var IsPakPassport = pk.passport;
45
51
  var IsVehiclePlate = pk.vehiclePlate;
52
+ var IsCodPhone = pk.codPhone;
46
53
 
47
- export { IsCNIC, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
54
+ export { IsCNIC, IsCodPhone, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { normalizeRomanUrdu, formatHijri, toHijri, formatPKR, formatLakh, parseAddress, getCityByPostalCode, getPostalCode, getProvince, getBankFromIBAN, validateIBAN, analyzePhone, validatePhone, validateCNIC } from 'pakdatakit';
3
3
 
4
4
  // package.json
5
- var version = "2.3.0";
5
+ var version = "2.5.0";
6
6
  var EXIT_OK = 0;
7
7
  var EXIT_NEGATIVE = 1;
8
8
  var EXIT_USAGE = 2;
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var chunkYPAWNWFD_cjs = require('./chunk-YPAWNWFD.cjs');
4
+ require('./chunk-E6GWBOKV.cjs');
5
+ require('./chunk-VPBMIYO2.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "mapCourierStatus", {
10
+ enumerable: true,
11
+ get: function () { return chunkYPAWNWFD_cjs.mapCourierStatus; }
12
+ });
13
+ Object.defineProperty(exports, "normalizeCityForCourier", {
14
+ enumerable: true,
15
+ get: function () { return chunkYPAWNWFD_cjs.normalizeCityForCourier; }
16
+ });
@@ -0,0 +1,51 @@
1
+ /** Couriers that {@link mapCourierStatus} knows about. */
2
+ type Courier = 'TCS' | 'Leopards' | 'PostEx' | 'M&P' | 'Trax' | 'BlueEx';
3
+ /**
4
+ * A courier's status in one vocabulary, from order to delivery or return.
5
+ *
6
+ * @experimental The set of values may change in a minor release while more
7
+ * couriers' status lists are added.
8
+ */
9
+ type CourierStatus = 'pending' | 'booked' | 'picked-up' | 'in-transit' | 'out-for-delivery' | 'attempted' | 'under-review' | 'delivered' | 'returning' | 'returned' | 'cancelled';
10
+ /**
11
+ * Maps a courier's own status (its name, numeric ID or code, as the courier
12
+ * documents it) to a {@link CourierStatus}.
13
+ *
14
+ * Matching ignores case and extra spaces. PostEx's "Attempt Made: <reason>"
15
+ * history messages map to `attempted`.
16
+ *
17
+ * Only statuses the courier documents publicly are mapped: PostEx's API
18
+ * guide and one Leopards status. TCS, M&P, Trax and BlueEx publish no list,
19
+ * so they always return `null`, as does any status not in the list. No API
20
+ * is called.
21
+ *
22
+ * @param courier - `TCS`, `Leopards`, `PostEx`, `M&P`, `Trax` or `BlueEx`
23
+ * (case-insensitive; `LCS`, `MnP` and `Blue Ex` are accepted)
24
+ * @param raw - The status as the courier returned it
25
+ * @returns The status, or `null`. Never throws.
26
+ * @experimental Only PostEx and one Leopards status are mapped so far. The
27
+ * mapping and the {@link CourierStatus} values may change in a minor release
28
+ * as other couriers' lists are added.
29
+ */
30
+ declare function mapCourierStatus(courier: string, raw: string | number): CourierStatus | null;
31
+ /**
32
+ * Maps the way a customer or a courier writes a city to the city's name in
33
+ * pakdatakit's city list, so orders can be matched against a courier's
34
+ * service list.
35
+ *
36
+ * Accepts the exact name in any case, short forms (`LHR`, `Khi`, `Pindi`,
37
+ * `Isb`, `FSD`), the old name Lyallpur, a trailing "city", and the main
38
+ * cities in Urdu script.
39
+ *
40
+ * @example
41
+ * normalizeCityForCourier('LHR'); // "Lahore"
42
+ * normalizeCityForCourier('lyallpur'); // "Faisalabad"
43
+ * normalizeCityForCourier('Karachi City'); // "Karachi"
44
+ * normalizeCityForCourier('Atlantis'); // null
45
+ *
46
+ * @returns A city from the city list, or `null`. Never throws.
47
+ */
48
+ declare function normalizeCityForCourier(input: string): string | null;
49
+
50
+ export { mapCourierStatus, normalizeCityForCourier };
51
+ export type { Courier, CourierStatus };
@@ -0,0 +1,51 @@
1
+ /** Couriers that {@link mapCourierStatus} knows about. */
2
+ type Courier = 'TCS' | 'Leopards' | 'PostEx' | 'M&P' | 'Trax' | 'BlueEx';
3
+ /**
4
+ * A courier's status in one vocabulary, from order to delivery or return.
5
+ *
6
+ * @experimental The set of values may change in a minor release while more
7
+ * couriers' status lists are added.
8
+ */
9
+ type CourierStatus = 'pending' | 'booked' | 'picked-up' | 'in-transit' | 'out-for-delivery' | 'attempted' | 'under-review' | 'delivered' | 'returning' | 'returned' | 'cancelled';
10
+ /**
11
+ * Maps a courier's own status (its name, numeric ID or code, as the courier
12
+ * documents it) to a {@link CourierStatus}.
13
+ *
14
+ * Matching ignores case and extra spaces. PostEx's "Attempt Made: <reason>"
15
+ * history messages map to `attempted`.
16
+ *
17
+ * Only statuses the courier documents publicly are mapped: PostEx's API
18
+ * guide and one Leopards status. TCS, M&P, Trax and BlueEx publish no list,
19
+ * so they always return `null`, as does any status not in the list. No API
20
+ * is called.
21
+ *
22
+ * @param courier - `TCS`, `Leopards`, `PostEx`, `M&P`, `Trax` or `BlueEx`
23
+ * (case-insensitive; `LCS`, `MnP` and `Blue Ex` are accepted)
24
+ * @param raw - The status as the courier returned it
25
+ * @returns The status, or `null`. Never throws.
26
+ * @experimental Only PostEx and one Leopards status are mapped so far. The
27
+ * mapping and the {@link CourierStatus} values may change in a minor release
28
+ * as other couriers' lists are added.
29
+ */
30
+ declare function mapCourierStatus(courier: string, raw: string | number): CourierStatus | null;
31
+ /**
32
+ * Maps the way a customer or a courier writes a city to the city's name in
33
+ * pakdatakit's city list, so orders can be matched against a courier's
34
+ * service list.
35
+ *
36
+ * Accepts the exact name in any case, short forms (`LHR`, `Khi`, `Pindi`,
37
+ * `Isb`, `FSD`), the old name Lyallpur, a trailing "city", and the main
38
+ * cities in Urdu script.
39
+ *
40
+ * @example
41
+ * normalizeCityForCourier('LHR'); // "Lahore"
42
+ * normalizeCityForCourier('lyallpur'); // "Faisalabad"
43
+ * normalizeCityForCourier('Karachi City'); // "Karachi"
44
+ * normalizeCityForCourier('Atlantis'); // null
45
+ *
46
+ * @returns A city from the city list, or `null`. Never throws.
47
+ */
48
+ declare function normalizeCityForCourier(input: string): string | null;
49
+
50
+ export { mapCourierStatus, normalizeCityForCourier };
51
+ export type { Courier, CourierStatus };
@@ -0,0 +1,3 @@
1
+ export { mapCourierStatus, normalizeCityForCourier } from './chunk-4GSBHJX6.js';
2
+ import './chunk-E2XU6NOW.js';
3
+ import './chunk-ENQ7O7VW.js';
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var chunk5UCRHVI4_cjs = require('./chunk-5UCRHVI4.cjs');
4
+ require('./chunk-CF6AMRBU.cjs');
5
+ require('./chunk-SF4ECUZ6.cjs');
6
+ require('./chunk-VPBMIYO2.cjs');
7
+
8
+
9
+
10
+ Object.defineProperty(exports, "FBR_DI_SPEC_VERSION", {
11
+ enumerable: true,
12
+ get: function () { return chunk5UCRHVI4_cjs.FBR_DI_SPEC_VERSION; }
13
+ });
14
+ Object.defineProperty(exports, "buildFbrInvoice", {
15
+ enumerable: true,
16
+ get: function () { return chunk5UCRHVI4_cjs.buildFbrInvoice; }
17
+ });
18
+ Object.defineProperty(exports, "expectedSalesTax", {
19
+ enumerable: true,
20
+ get: function () { return chunk5UCRHVI4_cjs.expectedSalesTax; }
21
+ });
22
+ Object.defineProperty(exports, "validateFbrInvoice", {
23
+ enumerable: true,
24
+ get: function () { return chunk5UCRHVI4_cjs.validateFbrInvoice; }
25
+ });
@@ -0,0 +1,170 @@
1
+ /** Version of PRAL's technical specification this module follows. */
2
+ declare const FBR_DI_SPEC_VERSION = "1.12";
3
+ /** `invoiceType` values in the specification. */
4
+ type FbrInvoiceType = 'Sale Invoice' | 'Debit Note';
5
+ /** `buyerRegistrationType` values in the specification. */
6
+ type FbrRegistrationType = 'Registered' | 'Unregistered';
7
+ /** One line of an invoice (spec §4.1, `items`). Amounts are in rupees. */
8
+ interface FbrInvoiceItem {
9
+ /** HS code, e.g. `0101.2100`. */
10
+ hsCode: string;
11
+ productDescription: string;
12
+ /** Rate as FBR's SaleTypeToRate API describes it: `18%`, `Rs.3`, `Exempt` … */
13
+ rate: string;
14
+ /** Unit of measure as in FBR's UoM API, e.g. `Numbers, pieces, units`. */
15
+ uoM: string;
16
+ /** Up to 4 decimals. */
17
+ quantity: number;
18
+ /** "Total Sales Value (Including Tax)". FBR's own samples send 0. */
19
+ totalValues: number;
20
+ valueSalesExcludingST: number;
21
+ /** Notified or retail price; required for Third Schedule goods. */
22
+ fixedNotifiedValueOrRetailPrice: number;
23
+ salesTaxApplicable: number;
24
+ salesTaxWithheldAtSource: number;
25
+ extraTax?: number;
26
+ furtherTax?: number;
27
+ /** Required when the rate is not 18% (error 0077). */
28
+ sroScheduleNo?: string;
29
+ fedPayable?: number;
30
+ discount?: number;
31
+ /** Sale type as in FBR's transaction type API, e.g. `Goods at standard rate (default)`. */
32
+ saleType: string;
33
+ /** Required when `sroScheduleNo` is given (error 0078). */
34
+ sroItemSerialNo?: string;
35
+ }
36
+ /** The invoice body for `postinvoicedata` and `validateinvoicedata` (spec §4.1, §4.2). */
37
+ interface FbrInvoice {
38
+ invoiceType: FbrInvoiceType;
39
+ /** `YYYY-MM-DD`. */
40
+ invoiceDate: string;
41
+ /** 7-digit NTN or 13-digit CNIC. */
42
+ sellerNTNCNIC: string;
43
+ sellerBusinessName: string;
44
+ sellerProvince: string;
45
+ sellerAddress: string;
46
+ /** 7-digit NTN or 13-digit CNIC; may be empty for an unregistered buyer. */
47
+ buyerNTNCNIC: string;
48
+ buyerBusinessName: string;
49
+ buyerProvince: string;
50
+ buyerAddress: string;
51
+ buyerRegistrationType: FbrRegistrationType;
52
+ /** FBR invoice number of the original invoice; required for a debit note. */
53
+ invoiceRefNo: string;
54
+ /** Sandbox only: `SN001` to `SN028`. */
55
+ scenarioId?: string;
56
+ items: FbrInvoiceItem[];
57
+ }
58
+ /** An item for {@link buildFbrInvoice}: the tax may be left out. */
59
+ type FbrInvoiceItemInput = Omit<FbrInvoiceItem, 'salesTaxApplicable' | 'salesTaxWithheldAtSource' | 'totalValues' | 'fixedNotifiedValueOrRetailPrice'> & {
60
+ salesTaxApplicable?: number;
61
+ salesTaxWithheldAtSource?: number;
62
+ totalValues?: number;
63
+ fixedNotifiedValueOrRetailPrice?: number;
64
+ };
65
+ /** Input for {@link buildFbrInvoice}. */
66
+ type FbrInvoiceInput = Omit<FbrInvoice, 'items' | 'invoiceRefNo' | 'buyerNTNCNIC'> & {
67
+ invoiceRefNo?: string;
68
+ buyerNTNCNIC?: string;
69
+ items: FbrInvoiceItemInput[];
70
+ };
71
+ /** Column totals of an invoice, in rupees. Not sent to FBR. */
72
+ interface FbrInvoiceTotals {
73
+ quantity: number;
74
+ valueSalesExcludingST: number;
75
+ salesTaxApplicable: number;
76
+ salesTaxWithheldAtSource: number;
77
+ extraTax: number;
78
+ furtherTax: number;
79
+ fedPayable: number;
80
+ discount: number;
81
+ }
82
+ /** Result of {@link buildFbrInvoice}. */
83
+ interface FbrInvoiceBuild {
84
+ invoice: FbrInvoice;
85
+ totals: FbrInvoiceTotals;
86
+ }
87
+ /** One problem found by {@link validateFbrInvoice}. */
88
+ interface FbrInvoiceError {
89
+ /**
90
+ * FBR's error code (spec §7 and the Error Message Guide), or `null` for a
91
+ * required field the specification gives no code for.
92
+ */
93
+ code: string | null;
94
+ /** Where: `invoiceDate`, `items[0].rate` … */
95
+ field: string;
96
+ message: string;
97
+ }
98
+ /** Result of {@link validateFbrInvoice}. */
99
+ interface FbrInvoiceValidation {
100
+ valid: boolean;
101
+ errors: FbrInvoiceError[];
102
+ }
103
+ /** Options for {@link validateFbrInvoice}. */
104
+ interface FbrInvoiceValidationOptions {
105
+ /** Today as `YYYY-MM-DD`, to reject invoices dated later (error 0043). Not checked when left out. */
106
+ today?: string;
107
+ }
108
+ /**
109
+ * The sales tax FBR expects on a line, in rupees, or `null` when the rate is
110
+ * not a plain percentage or per-unit amount (spec §7, errors 0102, 0104,
111
+ * 0105):
112
+ *
113
+ * - `N%` on Third Schedule goods: retail price × rate (0102);
114
+ * - `N%` otherwise: value excluding sales tax × rate (0104);
115
+ * - `Rs.N`: quantity × N (0105).
116
+ *
117
+ * Rounded half up to the paisa (the specification allows 2 decimals and
118
+ * gives no rounding rule).
119
+ */
120
+ declare function expectedSalesTax(item: {
121
+ rate: string;
122
+ saleType?: string;
123
+ quantity?: number;
124
+ valueSalesExcludingST?: number;
125
+ fixedNotifiedValueOrRetailPrice?: number;
126
+ }): number | null;
127
+ /**
128
+ * Builds an FBR digital invoice from your own fields, working out
129
+ * `salesTaxApplicable` on each line where you leave it out (see
130
+ * {@link expectedSalesTax}; uses `calculateSalesTax`). Lines with a rate
131
+ * that is neither `N%` nor `Rs.N` (`Exempt`, combined rates) get 0 unless you
132
+ * give the tax.
133
+ *
134
+ * `salesTaxWithheldAtSource`, `totalValues` and
135
+ * `fixedNotifiedValueOrRetailPrice` default to 0, and `invoiceRefNo` and
136
+ * `buyerNTNCNIC` to `""`, as in FBR's samples. Nothing else is filled in or
137
+ * changed; check the result with {@link validateFbrInvoice}.
138
+ *
139
+ * Also returns column totals, which are for your own records: the
140
+ * specification has no invoice-level totals.
141
+ *
142
+ * @returns The invoice and totals, or `null` if `input` is not an object
143
+ * with an `items` array. Never throws.
144
+ */
145
+ declare function buildFbrInvoice(input: FbrInvoiceInput): FbrInvoiceBuild | null;
146
+ /**
147
+ * Checks an FBR digital invoice against the rules of PRAL's specification
148
+ * (v1.12) and Error Message Guide that need no call to FBR, and returns every
149
+ * problem with FBR's error code.
150
+ *
151
+ * Checked: invoice type (0003, 0011), date format (0005, 0042, 0113) and,
152
+ * with `options.today`, a future date (0043); seller and buyer NTN/CNIC
153
+ * (0401, 0402, 0009), self-invoicing (0058), names, provinces (0073, 0074),
154
+ * addresses, buyer registration type (0012), the reference number of a debit
155
+ * note (0026), the sandbox scenario, and on each line: HS code (0044), rate
156
+ * (0020), unit, sale type (0013), required and valid amounts (0021, 0023,
157
+ * 0024, 0098, 0300, 0302), SRO schedule and serial (0077, 0078), Third
158
+ * Schedule retail price (0090), extra tax on reduced-rate goods (0091) and
159
+ * the sales tax arithmetic (0102, 0104, 0105, to within one paisa).
160
+ *
161
+ * Not checked, because they need FBR's data: registration status, whether a
162
+ * province, HS code, unit, rate, sale type or SRO is in FBR's lists or fits
163
+ * the others, and the original invoice of a debit note.
164
+ *
165
+ * @returns `{ valid, errors }`. Never throws.
166
+ */
167
+ declare function validateFbrInvoice(invoice: FbrInvoice, options?: FbrInvoiceValidationOptions): FbrInvoiceValidation;
168
+
169
+ export { FBR_DI_SPEC_VERSION, buildFbrInvoice, expectedSalesTax, validateFbrInvoice };
170
+ export type { FbrInvoice, FbrInvoiceBuild, FbrInvoiceError, FbrInvoiceInput, FbrInvoiceItem, FbrInvoiceItemInput, FbrInvoiceTotals, FbrInvoiceType, FbrInvoiceValidation, FbrInvoiceValidationOptions, FbrRegistrationType };