@ripwords/myinvois-client 0.1.5 → 0.1.7

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 (81) hide show
  1. package/package.json +8 -11
  2. package/.prettierrc +0 -8
  3. package/CHANGELOG.md +0 -140
  4. package/bun.lock +0 -460
  5. package/myinvois-cert.conf.template +0 -23
  6. package/scripts/gen-cert.sh +0 -159
  7. package/src/api/platform/platformLogin.ts +0 -34
  8. package/src/index.ts +0 -530
  9. package/src/types/classification-codes.d.ts +0 -115
  10. package/src/types/country-code.d.ts +0 -790
  11. package/src/types/currencies.d.ts +0 -383
  12. package/src/types/documents.d.ts +0 -869
  13. package/src/types/e-invoice.d.ts +0 -41
  14. package/src/types/index.d.ts +0 -24
  15. package/src/types/msic/0X.d.ts +0 -408
  16. package/src/types/msic/1X.d.ts +0 -210
  17. package/src/types/msic/2X.d.ts +0 -266
  18. package/src/types/msic/3X.d.ts +0 -114
  19. package/src/types/msic/4X.d.ts +0 -520
  20. package/src/types/msic/5X.d.ts +0 -144
  21. package/src/types/msic/6X.d.ts +0 -200
  22. package/src/types/msic/7X.d.ts +0 -132
  23. package/src/types/msic/8X.d.ts +0 -210
  24. package/src/types/msic/9X.d.ts +0 -186
  25. package/src/types/msic-codes.d.ts +0 -31
  26. package/src/types/payment-modes.d.ts +0 -41
  27. package/src/types/signatures.d.ts +0 -169
  28. package/src/types/state-codes.d.ts +0 -59
  29. package/src/types/tax-types.d.ts +0 -39
  30. package/src/types/unit/1X.d.ts +0 -16
  31. package/src/types/unit/2X.d.ts +0 -62
  32. package/src/types/unit/3X.d.ts +0 -17
  33. package/src/types/unit/4X.d.ts +0 -44
  34. package/src/types/unit/5X.d.ts +0 -26
  35. package/src/types/unit/6X.d.ts +0 -12
  36. package/src/types/unit/7X.d.ts +0 -12
  37. package/src/types/unit/8X.d.ts +0 -15
  38. package/src/types/unit/9X.d.ts +0 -11
  39. package/src/types/unit/AX.d.ts +0 -202
  40. package/src/types/unit/BX.d.ts +0 -212
  41. package/src/types/unit/CX.d.ts +0 -238
  42. package/src/types/unit/DX.d.ts +0 -212
  43. package/src/types/unit/EX.d.ts +0 -196
  44. package/src/types/unit/FX.d.ts +0 -236
  45. package/src/types/unit/GX.d.ts +0 -254
  46. package/src/types/unit/HX.d.ts +0 -234
  47. package/src/types/unit/IX.d.ts +0 -28
  48. package/src/types/unit/JX.d.ts +0 -190
  49. package/src/types/unit/KX.d.ts +0 -284
  50. package/src/types/unit/LX.d.ts +0 -228
  51. package/src/types/unit/MX.d.ts +0 -288
  52. package/src/types/unit/NX.d.ts +0 -226
  53. package/src/types/unit/OX.d.ts +0 -34
  54. package/src/types/unit/PX.d.ts +0 -224
  55. package/src/types/unit/QX.d.ts +0 -94
  56. package/src/types/unit/RX.d.ts +0 -28
  57. package/src/types/unit/SX.d.ts +0 -56
  58. package/src/types/unit/TX.d.ts +0 -44
  59. package/src/types/unit/UX.d.ts +0 -14
  60. package/src/types/unit/VX.d.ts +0 -13
  61. package/src/types/unit/WX.d.ts +0 -34
  62. package/src/types/unit/XX.d.ts +0 -825
  63. package/src/types/unit/YX.d.ts +0 -17
  64. package/src/types/unit/ZX.d.ts +0 -19
  65. package/src/types/unit-types.d.ts +0 -86
  66. package/src/utils/base64.ts +0 -7
  67. package/src/utils/certificate.ts +0 -60
  68. package/src/utils/document.ts +0 -852
  69. package/src/utils/getBaseUrl.ts +0 -5
  70. package/src/utils/helpers.ts +0 -552
  71. package/src/utils/signature-diagnostics.ts +0 -583
  72. package/src/utils/validation.ts +0 -268
  73. package/test/MyInvoiClientWithRealData.test.ts +0 -40
  74. package/test/MyInvoisClient.test.ts +0 -204
  75. package/test/base64.test.ts +0 -43
  76. package/test/dynamicInvoiceFeatures.test.ts +0 -451
  77. package/test/signAndSubmitInvoice.test.ts +0 -452
  78. package/test/signature-diagnostics.test.ts +0 -130
  79. package/tsconfig.json +0 -39
  80. package/tsdown.config.ts +0 -31
  81. package/vitest.config.ts +0 -8
@@ -1,159 +0,0 @@
1
- #!/bin/bash
2
-
3
- # MyInvois Test Certificate Generator
4
- # Generates self-signed certificates with required MyInvois fields for testing
5
-
6
- set -e # Exit on any error
7
-
8
- echo "🔐 MyInvois Test Certificate Generator"
9
- echo "======================================"
10
- echo ""
11
-
12
- # Check if OpenSSL is available
13
- if ! command -v openssl &> /dev/null; then
14
- echo "❌ Error: OpenSSL is not installed or not in PATH"
15
- echo "Please install OpenSSL first."
16
- exit 1
17
- fi
18
-
19
- echo "✅ OpenSSL found: $(openssl version)"
20
- echo ""
21
-
22
- # Get user input
23
- echo "📝 Please provide your certificate details:"
24
- echo ""
25
-
26
- read -p "Company Name (e.g., 'My Company Sdn Bhd'): " COMPANY_NAME
27
- read -p "State/Province (e.g., 'Kuala Lumpur'): " STATE
28
- read -p "City (e.g., 'Kuala Lumpur'): " CITY
29
- read -p "Email Address: " EMAIL
30
- read -p "Domain (optional, e.g., 'mycompany.com'): " DOMAIN
31
- read -p "Business Registration Number (e.g., '202301234567'): " BUSINESS_REG
32
- read -p "MyInvois TIN (e.g., 'IG12345678901'): " TIN
33
-
34
- echo ""
35
-
36
- # Validate required fields
37
- if [[ -z "$COMPANY_NAME" || -z "$STATE" || -z "$CITY" || -z "$EMAIL" || -z "$BUSINESS_REG" || -z "$TIN" ]]; then
38
- echo "❌ Error: All fields except domain are required"
39
- exit 1
40
- fi
41
-
42
- # Set default domain if not provided
43
- if [[ -z "$DOMAIN" ]]; then
44
- DOMAIN="localhost"
45
- fi
46
-
47
- echo "📋 Certificate Details:"
48
- echo " Company: $COMPANY_NAME"
49
- echo " State: $STATE"
50
- echo " City: $CITY"
51
- echo " Email: $EMAIL"
52
- echo " Domain: $DOMAIN"
53
- echo " Business Reg: $BUSINESS_REG"
54
- echo " TIN: $TIN"
55
- echo ""
56
-
57
- read -p "Continue with these details? (y/N): " CONFIRM
58
- if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
59
- echo "❌ Cancelled by user"
60
- exit 0
61
- fi
62
-
63
- echo ""
64
- echo "🔧 Generating certificate files..."
65
-
66
- # Create temporary config file
67
- CONFIG_FILE="myinvois-cert-temp.conf"
68
- cat > "$CONFIG_FILE" << EOF
69
- [req]
70
- distinguished_name = req_distinguished_name
71
- req_extensions = v3_req
72
- prompt = no
73
-
74
- [req_distinguished_name]
75
- C = MY
76
- ST = $STATE
77
- L = $CITY
78
- O = $COMPANY_NAME
79
- CN = $COMPANY_NAME
80
- emailAddress = $EMAIL
81
- serialNumber = $BUSINESS_REG
82
-
83
- [v3_req]
84
- keyUsage = keyEncipherment, dataEncipherment, digitalSignature, nonRepudiation
85
- extendedKeyUsage = clientAuth, emailProtection
86
- subjectAltName = @alt_names
87
-
88
- [alt_names]
89
- email.1 = $EMAIL
90
- DNS.1 = $DOMAIN
91
- EOF
92
-
93
- # Generate private key
94
- echo "🔑 Generating private key..."
95
- if openssl genrsa -out myinvois-test-key.pem 2048; then
96
- chmod 600 myinvois-test-key.pem
97
- echo "✅ Private key saved: myinvois-test-key.pem"
98
- else
99
- echo "❌ Failed to generate private key"
100
- exit 1
101
- fi
102
-
103
- # Generate basic certificate
104
- echo "📜 Generating basic certificate..."
105
- if openssl req -new -x509 -key myinvois-test-key.pem -out myinvois-test-cert.pem -days 365 -config "$CONFIG_FILE"; then
106
- echo "✅ Basic certificate saved: myinvois-test-cert.pem"
107
- else
108
- echo "❌ Failed to generate basic certificate"
109
- exit 1
110
- fi
111
-
112
- # Generate enhanced certificate with organizationIdentifier
113
- echo "🚀 Generating enhanced certificate with organizationIdentifier..."
114
- if openssl req -new -x509 -key myinvois-test-key.pem -out myinvois-enhanced-cert.pem -days 365 \
115
- -subj "/C=MY/ST=$STATE/L=$CITY/O=$COMPANY_NAME/CN=$COMPANY_NAME/serialNumber=$BUSINESS_REG/2.5.4.97=$TIN/emailAddress=$EMAIL"; then
116
- echo "✅ Enhanced certificate saved: myinvois-enhanced-cert.pem"
117
- else
118
- echo "❌ Failed to generate enhanced certificate"
119
- exit 1
120
- fi
121
-
122
- # Clean up temporary config
123
- rm "$CONFIG_FILE"
124
-
125
- echo ""
126
- echo "🔍 Verifying enhanced certificate..."
127
-
128
- # Verify the enhanced certificate has required fields
129
- if openssl x509 -in myinvois-enhanced-cert.pem -text -noout | grep -q "organizationIdentifier"; then
130
- echo "✅ organizationIdentifier field: Found"
131
- else
132
- echo "❌ organizationIdentifier field: Missing"
133
- fi
134
-
135
- if openssl x509 -in myinvois-enhanced-cert.pem -text -noout | grep -q "serialNumber"; then
136
- echo "✅ SERIALNUMBER field: Found"
137
- else
138
- echo "❌ SERIALNUMBER field: Missing"
139
- fi
140
-
141
- echo ""
142
- echo "📋 Certificate subject:"
143
- openssl x509 -in myinvois-enhanced-cert.pem -noout -subject | sed 's/subject=/ /'
144
-
145
- echo ""
146
- echo "🎉 Certificate generation complete!"
147
- echo ""
148
- echo "📁 Generated files:"
149
- echo " • myinvois-test-key.pem (private key - keep secure!)"
150
- echo " • myinvois-test-cert.pem (basic certificate)"
151
- echo " • myinvois-enhanced-cert.pem (with organizationIdentifier - recommended)"
152
- echo ""
153
- echo "💡 Next steps:"
154
- echo " 1. Use 'myinvois-enhanced-cert.pem' for testing MyInvois integration"
155
- echo " 2. Update your environment variables to use these files"
156
- echo " 3. For production, obtain official certificate from MyInvois-approved CA"
157
- echo ""
158
- echo "⚠️ Note: These are self-signed certificates for testing only!"
159
- echo " They will resolve DS306, DS307, DS309 errors but not CA trust issues."
@@ -1,34 +0,0 @@
1
- import type { ClientCredentials, TokenResponse } from '../../types'
2
-
3
- export const platformLogin = async (
4
- client: ClientCredentials,
5
- ): Promise<{
6
- token: string
7
- tokenExpiration: Date
8
- }> => {
9
- const { clientId, clientSecret, baseUrl, onBehalfOf, debug } = client
10
- try {
11
- const response = await fetch(`${baseUrl}/connect/token`, {
12
- method: 'POST',
13
- headers: {
14
- 'Content-Type': 'application/x-www-form-urlencoded',
15
- ...(onBehalfOf ? { onbehalfof: onBehalfOf } : {}),
16
- },
17
- body: new URLSearchParams({
18
- grant_type: 'client_credentials',
19
- client_id: clientId,
20
- client_secret: clientSecret,
21
- scope: 'InvoicingAPI',
22
- }),
23
- })
24
-
25
- const tokenResponse: TokenResponse = await response.json()
26
- return {
27
- token: tokenResponse.access_token,
28
- tokenExpiration: new Date(Date.now() + tokenResponse.expires_in * 1000),
29
- }
30
- } catch (error) {
31
- if (debug) console.error(error)
32
- throw error
33
- }
34
- }