@posx/core 5.5.393 → 5.5.396
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/build/index.d.ts +9 -0
- package/build/index.js +1 -1
- package/dev/escpos/receipt.bin +0 -0
- package/dev/escpos/receipt.hex +1 -0
- package/dev/escpos/receipt.json +1 -0
- package/dev/escpos-cli-usage.md +103 -0
- package/dev/px-cli.md +99 -0
- package/dev/tmp/xpos_product_import(1).csv +338 -0
- package/dev/tmp/xpos_product_import_fixed.csv +338 -0
- package/package.json +1 -1
- package/package.publish.json +3 -2
- package/px/.env.example +3 -0
- package/px/commands/category.ts +47 -0
- package/px/commands/product.ts +51 -0
- package/px/http.ts +40 -0
- package/px/index.ts +35 -0
package/px/http.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IServiceOptions } from '../src/types/misc.type'
|
|
2
|
+
|
|
3
|
+
const BASE_URL = process.env.PX_BASE_URL || 'https://lite-dev.posx.ai'
|
|
4
|
+
const API_KEY = process.env.PX_API_KEY || ''
|
|
5
|
+
const MERCHANT_UID = process.env.PX_MERCHANT_UID || ''
|
|
6
|
+
|
|
7
|
+
if (!API_KEY) { console.error('PX_API_KEY is required'); process.exit(1) }
|
|
8
|
+
if (!MERCHANT_UID) { console.error('PX_MERCHANT_UID is required'); process.exit(1) }
|
|
9
|
+
|
|
10
|
+
export const options: Pick<IServiceOptions, 'base_url' | 'merchant_uid'> = {
|
|
11
|
+
base_url: BASE_URL,
|
|
12
|
+
merchant_uid: MERCHANT_UID,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const headers = { 'x-api-key': API_KEY, 'Content-Type': 'application/json' }
|
|
16
|
+
const base = `${BASE_URL}/api/v5/merchants/${MERCHANT_UID}`
|
|
17
|
+
const sapiBase = `${BASE_URL}/sapi/v5/merchants/${MERCHANT_UID}`
|
|
18
|
+
|
|
19
|
+
async function request(method: string, url: string, body?: any) {
|
|
20
|
+
const res = await fetch(url, {
|
|
21
|
+
method,
|
|
22
|
+
headers,
|
|
23
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
24
|
+
})
|
|
25
|
+
const data = await res.json()
|
|
26
|
+
if (!res.ok) throw new Error(`${res.status}: ${JSON.stringify(data)}`)
|
|
27
|
+
return data
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const http = {
|
|
31
|
+
get: (path: string) => request('GET', `${base}/${path}`),
|
|
32
|
+
put: (path: string, body: any) => request('PUT', `${base}/${path}`, body),
|
|
33
|
+
patch: (path: string, body: any) => request('PATCH', `${base}/${path}`, body),
|
|
34
|
+
del: (path: string) => request('DELETE', `${base}/${path}`),
|
|
35
|
+
// AutoQuery endpoint using sapi base
|
|
36
|
+
autoquery: (path: string, params: Record<string, string>) => {
|
|
37
|
+
const qs = new URLSearchParams(params).toString()
|
|
38
|
+
return request('GET', `${sapiBase}/${path}${qs ? `?${qs}` : ''}`)
|
|
39
|
+
},
|
|
40
|
+
}
|
package/px/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as category from './commands/category'
|
|
2
|
+
import * as product from './commands/product'
|
|
3
|
+
|
|
4
|
+
const args = process.argv.slice(2)
|
|
5
|
+
const entity = args[0]
|
|
6
|
+
const action = args[1]
|
|
7
|
+
|
|
8
|
+
// Parse --key value pairs into an object
|
|
9
|
+
function parseOpts(args: string[]): Record<string, string> {
|
|
10
|
+
const opts: Record<string, string> = {}
|
|
11
|
+
for (let i = 2; i < args.length; i += 2)
|
|
12
|
+
if (args[i]?.startsWith('--')) opts[args[i].slice(2)] = args[i + 1] || ''
|
|
13
|
+
return opts
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const opts = parseOpts(args)
|
|
17
|
+
const commands: Record<string, Record<string, any>> = { category, product }
|
|
18
|
+
const ACTIONS = ['list', 'get', 'add', 'update', 'delete']
|
|
19
|
+
|
|
20
|
+
if (!entity || !commands[entity]) {
|
|
21
|
+
console.log('Usage: bun px/index.ts <category|product> <list|get|add|update|delete> [--key value ...]')
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
if (!action || !ACTIONS.includes(action)) {
|
|
25
|
+
console.log(`Actions: ${ACTIONS.join(', ')}`)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const mod = commands[entity]
|
|
30
|
+
const fn = action === 'delete' ? 'del' : action
|
|
31
|
+
|
|
32
|
+
if (fn === 'get' || fn === 'del') mod[fn](opts.id)
|
|
33
|
+
else if (fn === 'update') mod[fn](opts.id, opts)
|
|
34
|
+
else if (fn === 'add') mod[fn](opts)
|
|
35
|
+
else mod[fn](opts)
|