@ripwords/myinvois-client 0.1.6 → 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.
- package/package.json +5 -8
- package/.prettierrc +0 -8
- package/CHANGELOG.md +0 -152
- package/bun.lock +0 -460
- package/myinvois-cert.conf.template +0 -23
- package/scripts/gen-cert.sh +0 -159
- package/src/api/platform/platformLogin.ts +0 -34
- package/src/index.ts +0 -530
- package/src/types/classification-codes.d.ts +0 -115
- package/src/types/country-code.d.ts +0 -790
- package/src/types/currencies.d.ts +0 -383
- package/src/types/documents.d.ts +0 -869
- package/src/types/e-invoice.d.ts +0 -41
- package/src/types/index.d.ts +0 -24
- package/src/types/msic/0X.d.ts +0 -408
- package/src/types/msic/1X.d.ts +0 -210
- package/src/types/msic/2X.d.ts +0 -266
- package/src/types/msic/3X.d.ts +0 -114
- package/src/types/msic/4X.d.ts +0 -520
- package/src/types/msic/5X.d.ts +0 -144
- package/src/types/msic/6X.d.ts +0 -200
- package/src/types/msic/7X.d.ts +0 -132
- package/src/types/msic/8X.d.ts +0 -210
- package/src/types/msic/9X.d.ts +0 -186
- package/src/types/msic-codes.d.ts +0 -31
- package/src/types/payment-modes.d.ts +0 -41
- package/src/types/signatures.d.ts +0 -169
- package/src/types/state-codes.d.ts +0 -59
- package/src/types/tax-types.d.ts +0 -39
- package/src/types/unit/1X.d.ts +0 -16
- package/src/types/unit/2X.d.ts +0 -62
- package/src/types/unit/3X.d.ts +0 -17
- package/src/types/unit/4X.d.ts +0 -44
- package/src/types/unit/5X.d.ts +0 -26
- package/src/types/unit/6X.d.ts +0 -12
- package/src/types/unit/7X.d.ts +0 -12
- package/src/types/unit/8X.d.ts +0 -15
- package/src/types/unit/9X.d.ts +0 -11
- package/src/types/unit/AX.d.ts +0 -202
- package/src/types/unit/BX.d.ts +0 -212
- package/src/types/unit/CX.d.ts +0 -238
- package/src/types/unit/DX.d.ts +0 -212
- package/src/types/unit/EX.d.ts +0 -196
- package/src/types/unit/FX.d.ts +0 -236
- package/src/types/unit/GX.d.ts +0 -254
- package/src/types/unit/HX.d.ts +0 -234
- package/src/types/unit/IX.d.ts +0 -28
- package/src/types/unit/JX.d.ts +0 -190
- package/src/types/unit/KX.d.ts +0 -284
- package/src/types/unit/LX.d.ts +0 -228
- package/src/types/unit/MX.d.ts +0 -288
- package/src/types/unit/NX.d.ts +0 -226
- package/src/types/unit/OX.d.ts +0 -34
- package/src/types/unit/PX.d.ts +0 -224
- package/src/types/unit/QX.d.ts +0 -94
- package/src/types/unit/RX.d.ts +0 -28
- package/src/types/unit/SX.d.ts +0 -56
- package/src/types/unit/TX.d.ts +0 -44
- package/src/types/unit/UX.d.ts +0 -14
- package/src/types/unit/VX.d.ts +0 -13
- package/src/types/unit/WX.d.ts +0 -34
- package/src/types/unit/XX.d.ts +0 -825
- package/src/types/unit/YX.d.ts +0 -17
- package/src/types/unit/ZX.d.ts +0 -19
- package/src/types/unit-types.d.ts +0 -86
- package/src/utils/base64.ts +0 -7
- package/src/utils/certificate.ts +0 -60
- package/src/utils/document.ts +0 -852
- package/src/utils/getBaseUrl.ts +0 -5
- package/src/utils/helpers.ts +0 -552
- package/src/utils/signature-diagnostics.ts +0 -583
- package/src/utils/validation.ts +0 -268
- package/test/MyInvoiClientWithRealData.test.ts +0 -40
- package/test/MyInvoisClient.test.ts +0 -204
- package/test/base64.test.ts +0 -43
- package/test/dynamicInvoiceFeatures.test.ts +0 -451
- package/test/signAndSubmitInvoice.test.ts +0 -452
- package/test/signature-diagnostics.test.ts +0 -130
- package/tsconfig.json +0 -39
- package/tsdown.config.ts +0 -31
- package/vitest.config.ts +0 -8
package/scripts/gen-cert.sh
DELETED
|
@@ -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
|
-
}
|