@blob-solutions/vcr-am-sdk 0.1.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.
- package/lib/index.cjs +2 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +108 -0
- package/lib/index.d.ts +108 -0
- package/lib/index.global.js +35 -0
- package/lib/index.global.js.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/package.json +60 -0
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var i in t)o(e,i,{get:t[i],enumerable:!0})},m=(e,t,i,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of l(t))!y.call(e,s)&&s!==i&&o(e,s,{get:()=>t[s],enumerable:!(u=c(t,s))||u.enumerable});return e};var g=e=>m(o({},"__esModule",{value:!0}),e);var I={};d(I,{AVAILABLE_LANGUAGES:()=>b,VCRClient:()=>a,unitsKeys:()=>D});module.exports=g(I);var r=require("simple-typed-fetch"),n=require("zod"),A="https://vcr.am/api/v1",f=n.z.object({saleId:n.z.number(),crn:n.z.string(),srcReceiptId:n.z.number().int(),fiscal:n.z.string()}),a=class{constructor(t){this.apiKey=t}async registerSale(t){return await(0,r.simpleFetch)(async()=>await(0,r.fetchWithValidation)(`${A}/sales`,f,{method:"POST",headers:{"x-api-key":this.apiKey,"Content-Type":"application/json"},body:JSON.stringify(t)},n.z.object({error:n.z.string()})))()}};var D=["pc","unit","set","box","pack","case","hr","sess","proj","sub","kg","l","m","g","ml","cm","bottle","can","jar","bag","m2","dozen","pair","mm","roll","tube","km","ton","m3","pallet","other"],b=["hy","ru","en"];
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/VCRClient.ts","../src/constants.ts"],"sourcesContent":["export { default as VCRClient } from \"./VCRClient\";\nexport * from \"./types\";\nexport * from \"./constants\";\n","import { fetchWithValidation, simpleFetch } from \"simple-typed-fetch\";\nimport { z } from \"zod\";\n\nimport type { SaleData } from \"./types\";\n\nconst API_URL = \"https://vcr.am/api/v1\";\n\nconst saleResponseSchema = z.object({\n saleId: z.number(),\n crn: z.string(),\n srcReceiptId: z.number().int(),\n fiscal: z.string(),\n});\n\nexport default class VCRClient {\n constructor(private readonly apiKey: string) {}\n\n async registerSale(data: SaleData) {\n const responseData = await simpleFetch(\n async () =>\n await fetchWithValidation(\n `${API_URL}/sales`,\n saleResponseSchema,\n {\n method: \"POST\",\n headers: {\n \"x-api-key\": this.apiKey,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(data),\n },\n z.object({\n error: z.string(),\n })\n )\n )();\n\n return responseData;\n }\n}\n","export const unitsKeys = [\n \"pc\",\n \"unit\",\n \"set\",\n \"box\",\n \"pack\",\n \"case\",\n \"hr\",\n \"sess\",\n \"proj\",\n \"sub\",\n \"kg\",\n \"l\",\n \"m\",\n \"g\",\n \"ml\",\n \"cm\",\n \"bottle\",\n \"can\",\n \"jar\",\n \"bag\",\n \"m2\",\n \"dozen\",\n \"pair\",\n \"mm\",\n \"roll\",\n \"tube\",\n \"km\",\n \"ton\",\n \"m3\",\n \"pallet\",\n \"other\",\n] as const;\n\nexport const AVAILABLE_LANGUAGES = [\"hy\", \"ru\", \"en\"] as const;\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,cAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAiD,8BACjDC,EAAkB,eAIZC,EAAU,wBAEVC,EAAqB,IAAE,OAAO,CAClC,OAAQ,IAAE,OAAO,EACjB,IAAK,IAAE,OAAO,EACd,aAAc,IAAE,OAAO,EAAE,IAAI,EAC7B,OAAQ,IAAE,OAAO,CACnB,CAAC,EAEoBC,EAArB,KAA+B,CAC7B,YAA6BC,EAAgB,CAAhB,YAAAA,CAAiB,CAE9C,MAAM,aAAaC,EAAgB,CAoBjC,OAnBqB,QAAM,eACzB,SACE,QAAM,uBACJ,GAAGJ,CAAO,SACVC,EACA,CACE,OAAQ,OACR,QAAS,CACP,YAAa,KAAK,OAClB,eAAgB,kBAClB,EACA,KAAM,KAAK,UAAUG,CAAI,CAC3B,EACA,IAAE,OAAO,CACP,MAAO,IAAE,OAAO,CAClB,CAAC,CACH,CACJ,EAAE,CAGJ,CACF,ECvCO,IAAMC,EAAY,CACvB,KACA,OACA,MACA,MACA,OACA,OACA,KACA,OACA,OACA,MACA,KACA,IACA,IACA,IACA,KACA,KACA,SACA,MACA,MACA,MACA,KACA,QACA,OACA,KACA,OACA,OACA,KACA,MACA,KACA,SACA,OACF,EAEaC,EAAsB,CAAC,KAAM,KAAM,IAAI","names":["src_exports","__export","AVAILABLE_LANGUAGES","VCRClient","unitsKeys","__toCommonJS","import_simple_typed_fetch","import_zod","API_URL","saleResponseSchema","VCRClient","apiKey","data","unitsKeys","AVAILABLE_LANGUAGES"]}
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { RequireAtLeastOne } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
declare const unitsKeys: readonly ["pc", "unit", "set", "box", "pack", "case", "hr", "sess", "proj", "sub", "kg", "l", "m", "g", "ml", "cm", "bottle", "can", "jar", "bag", "m2", "dozen", "pair", "mm", "roll", "tube", "km", "ton", "m3", "pallet", "other"];
|
|
4
|
+
declare const AVAILABLE_LANGUAGES: readonly ["hy", "ru", "en"];
|
|
5
|
+
|
|
6
|
+
type CashierInternalId = {
|
|
7
|
+
id: number;
|
|
8
|
+
};
|
|
9
|
+
type CashierDeskId = {
|
|
10
|
+
deskId: string;
|
|
11
|
+
};
|
|
12
|
+
type CashierId = CashierInternalId | CashierDeskId;
|
|
13
|
+
type Unit = (typeof unitsKeys)[number];
|
|
14
|
+
type Language = (typeof AVAILABLE_LANGUAGES)[number];
|
|
15
|
+
type PercentDiscount = {
|
|
16
|
+
type: "percent";
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
19
|
+
type AbsoluteDiscount = {
|
|
20
|
+
type: "price" | "total";
|
|
21
|
+
value: string;
|
|
22
|
+
};
|
|
23
|
+
type AbsoluteAdditionalDiscount = {
|
|
24
|
+
type: "total";
|
|
25
|
+
value: string;
|
|
26
|
+
};
|
|
27
|
+
type BaseDiscount = PercentDiscount | AbsoluteDiscount;
|
|
28
|
+
type AdditionalDiscount = PercentDiscount | AbsoluteAdditionalDiscount;
|
|
29
|
+
type NoDiscounts = {
|
|
30
|
+
base?: BaseDiscount;
|
|
31
|
+
additional?: AdditionalDiscount;
|
|
32
|
+
};
|
|
33
|
+
type BaseDiscounts = {
|
|
34
|
+
base: BaseDiscount;
|
|
35
|
+
};
|
|
36
|
+
type BaseAndAdditionalDiscounts = {
|
|
37
|
+
base: BaseDiscount;
|
|
38
|
+
additional: AdditionalDiscount;
|
|
39
|
+
};
|
|
40
|
+
type ExistingOffer = {
|
|
41
|
+
externalId: string;
|
|
42
|
+
};
|
|
43
|
+
type NewOffer = {
|
|
44
|
+
title: {
|
|
45
|
+
content: Partial<Record<Language, string>> & {
|
|
46
|
+
hy: string;
|
|
47
|
+
};
|
|
48
|
+
localizationStrategy: "translation" | "transliteration";
|
|
49
|
+
};
|
|
50
|
+
type: "product" | "service";
|
|
51
|
+
classifierCode: string;
|
|
52
|
+
defaultMeasureUnit: Unit;
|
|
53
|
+
defaultDepartment: {
|
|
54
|
+
internalId: number;
|
|
55
|
+
};
|
|
56
|
+
externalId: string;
|
|
57
|
+
};
|
|
58
|
+
type Offer = NewOffer | ExistingOffer;
|
|
59
|
+
type SaleItem = {
|
|
60
|
+
offer: Offer;
|
|
61
|
+
department: {
|
|
62
|
+
internalId: number;
|
|
63
|
+
};
|
|
64
|
+
quantity: string;
|
|
65
|
+
price: string;
|
|
66
|
+
unit: Unit;
|
|
67
|
+
discounts?: NoDiscounts | BaseDiscounts | BaseAndAdditionalDiscounts;
|
|
68
|
+
totalAmountTolerance?: string;
|
|
69
|
+
};
|
|
70
|
+
type SaleAmount = RequireAtLeastOne<{
|
|
71
|
+
prePayment?: string;
|
|
72
|
+
compensation?: string;
|
|
73
|
+
nonCash?: string;
|
|
74
|
+
cash?: string;
|
|
75
|
+
}>;
|
|
76
|
+
type SendReceiptToBuyer = {
|
|
77
|
+
email: string;
|
|
78
|
+
language: Language;
|
|
79
|
+
};
|
|
80
|
+
type IndividualBuyer = {
|
|
81
|
+
type: "individual";
|
|
82
|
+
receipt?: SendReceiptToBuyer;
|
|
83
|
+
};
|
|
84
|
+
type LegalEntityBuyer = {
|
|
85
|
+
type: "business_entity";
|
|
86
|
+
tin: string;
|
|
87
|
+
receipt?: SendReceiptToBuyer;
|
|
88
|
+
};
|
|
89
|
+
type Buyer = IndividualBuyer | LegalEntityBuyer;
|
|
90
|
+
type SaleData = {
|
|
91
|
+
cashier: CashierId;
|
|
92
|
+
items: SaleItem[];
|
|
93
|
+
amount: SaleAmount;
|
|
94
|
+
buyer: Buyer;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare class VCRClient {
|
|
98
|
+
private readonly apiKey;
|
|
99
|
+
constructor(apiKey: string);
|
|
100
|
+
registerSale(data: SaleData): Promise<{
|
|
101
|
+
saleId: number;
|
|
102
|
+
crn: string;
|
|
103
|
+
srcReceiptId: number;
|
|
104
|
+
fiscal: string;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { AVAILABLE_LANGUAGES, type SaleData, type SaleItem, type Unit, VCRClient, unitsKeys };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { RequireAtLeastOne } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
declare const unitsKeys: readonly ["pc", "unit", "set", "box", "pack", "case", "hr", "sess", "proj", "sub", "kg", "l", "m", "g", "ml", "cm", "bottle", "can", "jar", "bag", "m2", "dozen", "pair", "mm", "roll", "tube", "km", "ton", "m3", "pallet", "other"];
|
|
4
|
+
declare const AVAILABLE_LANGUAGES: readonly ["hy", "ru", "en"];
|
|
5
|
+
|
|
6
|
+
type CashierInternalId = {
|
|
7
|
+
id: number;
|
|
8
|
+
};
|
|
9
|
+
type CashierDeskId = {
|
|
10
|
+
deskId: string;
|
|
11
|
+
};
|
|
12
|
+
type CashierId = CashierInternalId | CashierDeskId;
|
|
13
|
+
type Unit = (typeof unitsKeys)[number];
|
|
14
|
+
type Language = (typeof AVAILABLE_LANGUAGES)[number];
|
|
15
|
+
type PercentDiscount = {
|
|
16
|
+
type: "percent";
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
19
|
+
type AbsoluteDiscount = {
|
|
20
|
+
type: "price" | "total";
|
|
21
|
+
value: string;
|
|
22
|
+
};
|
|
23
|
+
type AbsoluteAdditionalDiscount = {
|
|
24
|
+
type: "total";
|
|
25
|
+
value: string;
|
|
26
|
+
};
|
|
27
|
+
type BaseDiscount = PercentDiscount | AbsoluteDiscount;
|
|
28
|
+
type AdditionalDiscount = PercentDiscount | AbsoluteAdditionalDiscount;
|
|
29
|
+
type NoDiscounts = {
|
|
30
|
+
base?: BaseDiscount;
|
|
31
|
+
additional?: AdditionalDiscount;
|
|
32
|
+
};
|
|
33
|
+
type BaseDiscounts = {
|
|
34
|
+
base: BaseDiscount;
|
|
35
|
+
};
|
|
36
|
+
type BaseAndAdditionalDiscounts = {
|
|
37
|
+
base: BaseDiscount;
|
|
38
|
+
additional: AdditionalDiscount;
|
|
39
|
+
};
|
|
40
|
+
type ExistingOffer = {
|
|
41
|
+
externalId: string;
|
|
42
|
+
};
|
|
43
|
+
type NewOffer = {
|
|
44
|
+
title: {
|
|
45
|
+
content: Partial<Record<Language, string>> & {
|
|
46
|
+
hy: string;
|
|
47
|
+
};
|
|
48
|
+
localizationStrategy: "translation" | "transliteration";
|
|
49
|
+
};
|
|
50
|
+
type: "product" | "service";
|
|
51
|
+
classifierCode: string;
|
|
52
|
+
defaultMeasureUnit: Unit;
|
|
53
|
+
defaultDepartment: {
|
|
54
|
+
internalId: number;
|
|
55
|
+
};
|
|
56
|
+
externalId: string;
|
|
57
|
+
};
|
|
58
|
+
type Offer = NewOffer | ExistingOffer;
|
|
59
|
+
type SaleItem = {
|
|
60
|
+
offer: Offer;
|
|
61
|
+
department: {
|
|
62
|
+
internalId: number;
|
|
63
|
+
};
|
|
64
|
+
quantity: string;
|
|
65
|
+
price: string;
|
|
66
|
+
unit: Unit;
|
|
67
|
+
discounts?: NoDiscounts | BaseDiscounts | BaseAndAdditionalDiscounts;
|
|
68
|
+
totalAmountTolerance?: string;
|
|
69
|
+
};
|
|
70
|
+
type SaleAmount = RequireAtLeastOne<{
|
|
71
|
+
prePayment?: string;
|
|
72
|
+
compensation?: string;
|
|
73
|
+
nonCash?: string;
|
|
74
|
+
cash?: string;
|
|
75
|
+
}>;
|
|
76
|
+
type SendReceiptToBuyer = {
|
|
77
|
+
email: string;
|
|
78
|
+
language: Language;
|
|
79
|
+
};
|
|
80
|
+
type IndividualBuyer = {
|
|
81
|
+
type: "individual";
|
|
82
|
+
receipt?: SendReceiptToBuyer;
|
|
83
|
+
};
|
|
84
|
+
type LegalEntityBuyer = {
|
|
85
|
+
type: "business_entity";
|
|
86
|
+
tin: string;
|
|
87
|
+
receipt?: SendReceiptToBuyer;
|
|
88
|
+
};
|
|
89
|
+
type Buyer = IndividualBuyer | LegalEntityBuyer;
|
|
90
|
+
type SaleData = {
|
|
91
|
+
cashier: CashierId;
|
|
92
|
+
items: SaleItem[];
|
|
93
|
+
amount: SaleAmount;
|
|
94
|
+
buyer: Buyer;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
declare class VCRClient {
|
|
98
|
+
private readonly apiKey;
|
|
99
|
+
constructor(apiKey: string);
|
|
100
|
+
registerSale(data: SaleData): Promise<{
|
|
101
|
+
saleId: number;
|
|
102
|
+
crn: string;
|
|
103
|
+
srcReceiptId: number;
|
|
104
|
+
fiscal: string;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { AVAILABLE_LANGUAGES, type SaleData, type SaleItem, type Unit, VCRClient, unitsKeys };
|