@munchi_oy/license-sdk 0.4.0 → 0.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.
- package/README.md +2 -0
- package/dist/index.cjs +57 -2
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +53 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,3 +32,5 @@ const snapshot = await license.entitlements(venueId); // full snapshot, null = u
|
|
|
32
32
|
Call `invalidate(venueId)` when you receive a `license.changed` event.
|
|
33
33
|
|
|
34
34
|
It also exports the shared names: `PRODUCTS` and `PLANS` (catalog codes), `USAGE_METRICS` (what usage can cost money) and `REQUESTABLE_PRODUCTS` (what a store asks Munchi for in the dashboard: `ari`, `business_account`, `capital`).
|
|
35
|
+
|
|
36
|
+
For a group's company (ADR 0025) it exports `companyIds(country, { businessId, vatId })` (the IDs to store by the company's country, or `{ invalid: "businessId" | "vatId" }`; any country is accepted, Finland's are checked), `finnishBusinessId(input)` (the Y-tunnus as `NNNNNNN-C`, or `null` when its format or check digit is wrong), `finnishVatId(businessId)` (`FI` and its digits), and the types `LegalEntityChange` (the body of `PATCH /v1/accounts/:accountId/legal-entities/:legalEntityId`) and `LegalEntity` (its response).
|
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,10 @@ __export(index_exports, {
|
|
|
26
26
|
PRODUCTS: () => PRODUCTS,
|
|
27
27
|
REQUESTABLE_PRODUCTS: () => REQUESTABLE_PRODUCTS,
|
|
28
28
|
USAGE_METRICS: () => USAGE_METRICS,
|
|
29
|
-
USAGE_METRIC_NAMES: () => USAGE_METRIC_NAMES
|
|
29
|
+
USAGE_METRIC_NAMES: () => USAGE_METRIC_NAMES,
|
|
30
|
+
companyIds: () => companyIds,
|
|
31
|
+
finnishBusinessId: () => finnishBusinessId,
|
|
32
|
+
finnishVatId: () => finnishVatId
|
|
30
33
|
});
|
|
31
34
|
module.exports = __toCommonJS(index_exports);
|
|
32
35
|
|
|
@@ -45,6 +48,55 @@ var PLANS = [
|
|
|
45
48
|
PRODUCTS.one
|
|
46
49
|
];
|
|
47
50
|
|
|
51
|
+
// ../license-core/src/legal-entity.ts
|
|
52
|
+
var Y_TUNNUS = /^(\d{6,7})-(\d)$/;
|
|
53
|
+
var Y_TUNNUS_WEIGHTS = [
|
|
54
|
+
7,
|
|
55
|
+
9,
|
|
56
|
+
10,
|
|
57
|
+
5,
|
|
58
|
+
8,
|
|
59
|
+
4,
|
|
60
|
+
2
|
|
61
|
+
];
|
|
62
|
+
var finnishBusinessId = /* @__PURE__ */ __name((input) => {
|
|
63
|
+
const [, body, check] = Y_TUNNUS.exec(input.trim()) ?? [];
|
|
64
|
+
if (body === void 0 || check === void 0) return null;
|
|
65
|
+
const digits = body.padStart(7, "0");
|
|
66
|
+
const remainder = Y_TUNNUS_WEIGHTS.reduce((sum, weight, index) => sum + weight * Number(digits[index]), 0) % 11;
|
|
67
|
+
const expected = remainder === 0 ? 0 : 11 - remainder;
|
|
68
|
+
return Number(check) === expected ? `${digits}-${check}` : null;
|
|
69
|
+
}, "finnishBusinessId");
|
|
70
|
+
var finnishVatId = /* @__PURE__ */ __name((businessId) => `FI${businessId.replace("-", "")}`, "finnishVatId");
|
|
71
|
+
var ANY_COUNTRY = {
|
|
72
|
+
businessId: /* @__PURE__ */ __name((input) => input.trim() || null, "businessId"),
|
|
73
|
+
vatId: /* @__PURE__ */ __name((_businessId, input) => input?.trim() || null, "vatId")
|
|
74
|
+
};
|
|
75
|
+
var COMPANY_IDS_BY_COUNTRY = {
|
|
76
|
+
FI: {
|
|
77
|
+
businessId: finnishBusinessId,
|
|
78
|
+
vatId: /* @__PURE__ */ __name((businessId, input) => {
|
|
79
|
+
const vatId = finnishVatId(businessId);
|
|
80
|
+
return input === null || input.replace(/\s/g, "").toUpperCase() === vatId ? vatId : void 0;
|
|
81
|
+
}, "vatId")
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var companyIds = /* @__PURE__ */ __name((country, input) => {
|
|
85
|
+
const rules = COMPANY_IDS_BY_COUNTRY[country.toUpperCase()] ?? ANY_COUNTRY;
|
|
86
|
+
const businessId = rules.businessId(input.businessId);
|
|
87
|
+
if (businessId === null) return {
|
|
88
|
+
invalid: "businessId"
|
|
89
|
+
};
|
|
90
|
+
const vatId = rules.vatId(businessId, input.vatId ?? null);
|
|
91
|
+
if (vatId === void 0) return {
|
|
92
|
+
invalid: "vatId"
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
businessId,
|
|
96
|
+
vatId
|
|
97
|
+
};
|
|
98
|
+
}, "companyIds");
|
|
99
|
+
|
|
48
100
|
// ../license-core/src/requestable-products.ts
|
|
49
101
|
var REQUESTABLE_PRODUCTS = [
|
|
50
102
|
"ari",
|
|
@@ -204,5 +256,8 @@ var LicenseClient = class {
|
|
|
204
256
|
PRODUCTS,
|
|
205
257
|
REQUESTABLE_PRODUCTS,
|
|
206
258
|
USAGE_METRICS,
|
|
207
|
-
USAGE_METRIC_NAMES
|
|
259
|
+
USAGE_METRIC_NAMES,
|
|
260
|
+
companyIds,
|
|
261
|
+
finnishBusinessId,
|
|
262
|
+
finnishVatId
|
|
208
263
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,54 @@ type KnownProductCode = (typeof PRODUCTS)[keyof typeof PRODUCTS];
|
|
|
16
16
|
declare const PLANS: readonly ["MUN-START", "MUN-ONE"];
|
|
17
17
|
type PlanCode = (typeof PLANS)[number];
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A group's company (legal entity), as the dashboard reads and changes it. One company can be the
|
|
21
|
+
* company of several stores of the same group. Zero-dependency on purpose: the SDK ships it.
|
|
22
|
+
*/
|
|
23
|
+
interface LegalEntity {
|
|
24
|
+
legalEntityId: string;
|
|
25
|
+
accountId: string;
|
|
26
|
+
/** ISO 3166-1 alpha-2. Not changeable: Stripe Tax and the store's notices follow it. */
|
|
27
|
+
country: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** The country's company ID: the Y-tunnus (`NNNNNNN-C`) in Finland. */
|
|
30
|
+
businessId: string | null;
|
|
31
|
+
vatId: string | null;
|
|
32
|
+
/** The group's open stores that use this company. */
|
|
33
|
+
stores: Array<{
|
|
34
|
+
locationId: string;
|
|
35
|
+
venueId: number | null;
|
|
36
|
+
name: string;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** Body of `PATCH /v1/accounts/:accountId/legal-entities/:legalEntityId`. */
|
|
40
|
+
interface LegalEntityChange {
|
|
41
|
+
name: string;
|
|
42
|
+
businessId: string;
|
|
43
|
+
/** Omitted or `null`: derived where the country has a rule (`FI` + the Y-tunnus digits), else none. */
|
|
44
|
+
vatId?: string | null;
|
|
45
|
+
actorUserId: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The Finnish business ID (Y-tunnus) as `NNNNNNN-C`, or `null` when its format or check digit is
|
|
49
|
+
* wrong. Old six-digit IDs get the leading zero they are officially written with.
|
|
50
|
+
*/
|
|
51
|
+
declare const finnishBusinessId: (input: string) => string | null;
|
|
52
|
+
/** A Finnish VAT ID is always `FI` and the business ID's eight digits. */
|
|
53
|
+
declare const finnishVatId: (businessId: string) => string;
|
|
54
|
+
/** The IDs to store, or the field that is wrong for the company's country. */
|
|
55
|
+
type CompanyIds = {
|
|
56
|
+
businessId: string;
|
|
57
|
+
vatId: string | null;
|
|
58
|
+
} | {
|
|
59
|
+
invalid: "businessId" | "vatId";
|
|
60
|
+
};
|
|
61
|
+
/** Checks and normalises a company's IDs by the rules of its country (ISO 3166-1 alpha-2). */
|
|
62
|
+
declare const companyIds: (country: string, input: {
|
|
63
|
+
businessId: string;
|
|
64
|
+
vatId?: string | null;
|
|
65
|
+
}) => CompanyIds;
|
|
66
|
+
|
|
19
67
|
/**
|
|
20
68
|
* Products a store asks Munchi for in the dashboard because they can't be bought online
|
|
21
69
|
* (ADR 0022). These are the dashboard's product ids, not catalog codes (`MUN-*`); the mobile app
|
|
@@ -174,4 +222,4 @@ declare class LicenseClient {
|
|
|
174
222
|
private report;
|
|
175
223
|
}
|
|
176
224
|
|
|
177
|
-
export { type DeniedEvent, type KnownProductCode, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, REQUESTABLE_PRODUCTS, type RequestableProduct, type Snapshot, USAGE_METRICS, USAGE_METRIC_NAMES, type UsageMetric };
|
|
225
|
+
export { type CompanyIds, type DeniedEvent, type KnownProductCode, type LegalEntity, type LegalEntityChange, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, REQUESTABLE_PRODUCTS, type RequestableProduct, type Snapshot, USAGE_METRICS, USAGE_METRIC_NAMES, type UsageMetric, companyIds, finnishBusinessId, finnishVatId };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,54 @@ type KnownProductCode = (typeof PRODUCTS)[keyof typeof PRODUCTS];
|
|
|
16
16
|
declare const PLANS: readonly ["MUN-START", "MUN-ONE"];
|
|
17
17
|
type PlanCode = (typeof PLANS)[number];
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A group's company (legal entity), as the dashboard reads and changes it. One company can be the
|
|
21
|
+
* company of several stores of the same group. Zero-dependency on purpose: the SDK ships it.
|
|
22
|
+
*/
|
|
23
|
+
interface LegalEntity {
|
|
24
|
+
legalEntityId: string;
|
|
25
|
+
accountId: string;
|
|
26
|
+
/** ISO 3166-1 alpha-2. Not changeable: Stripe Tax and the store's notices follow it. */
|
|
27
|
+
country: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** The country's company ID: the Y-tunnus (`NNNNNNN-C`) in Finland. */
|
|
30
|
+
businessId: string | null;
|
|
31
|
+
vatId: string | null;
|
|
32
|
+
/** The group's open stores that use this company. */
|
|
33
|
+
stores: Array<{
|
|
34
|
+
locationId: string;
|
|
35
|
+
venueId: number | null;
|
|
36
|
+
name: string;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** Body of `PATCH /v1/accounts/:accountId/legal-entities/:legalEntityId`. */
|
|
40
|
+
interface LegalEntityChange {
|
|
41
|
+
name: string;
|
|
42
|
+
businessId: string;
|
|
43
|
+
/** Omitted or `null`: derived where the country has a rule (`FI` + the Y-tunnus digits), else none. */
|
|
44
|
+
vatId?: string | null;
|
|
45
|
+
actorUserId: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The Finnish business ID (Y-tunnus) as `NNNNNNN-C`, or `null` when its format or check digit is
|
|
49
|
+
* wrong. Old six-digit IDs get the leading zero they are officially written with.
|
|
50
|
+
*/
|
|
51
|
+
declare const finnishBusinessId: (input: string) => string | null;
|
|
52
|
+
/** A Finnish VAT ID is always `FI` and the business ID's eight digits. */
|
|
53
|
+
declare const finnishVatId: (businessId: string) => string;
|
|
54
|
+
/** The IDs to store, or the field that is wrong for the company's country. */
|
|
55
|
+
type CompanyIds = {
|
|
56
|
+
businessId: string;
|
|
57
|
+
vatId: string | null;
|
|
58
|
+
} | {
|
|
59
|
+
invalid: "businessId" | "vatId";
|
|
60
|
+
};
|
|
61
|
+
/** Checks and normalises a company's IDs by the rules of its country (ISO 3166-1 alpha-2). */
|
|
62
|
+
declare const companyIds: (country: string, input: {
|
|
63
|
+
businessId: string;
|
|
64
|
+
vatId?: string | null;
|
|
65
|
+
}) => CompanyIds;
|
|
66
|
+
|
|
19
67
|
/**
|
|
20
68
|
* Products a store asks Munchi for in the dashboard because they can't be bought online
|
|
21
69
|
* (ADR 0022). These are the dashboard's product ids, not catalog codes (`MUN-*`); the mobile app
|
|
@@ -174,4 +222,4 @@ declare class LicenseClient {
|
|
|
174
222
|
private report;
|
|
175
223
|
}
|
|
176
224
|
|
|
177
|
-
export { type DeniedEvent, type KnownProductCode, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, REQUESTABLE_PRODUCTS, type RequestableProduct, type Snapshot, USAGE_METRICS, USAGE_METRIC_NAMES, type UsageMetric };
|
|
225
|
+
export { type CompanyIds, type DeniedEvent, type KnownProductCode, type LegalEntity, type LegalEntityChange, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, REQUESTABLE_PRODUCTS, type RequestableProduct, type Snapshot, USAGE_METRICS, USAGE_METRIC_NAMES, type UsageMetric, companyIds, finnishBusinessId, finnishVatId };
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,55 @@ var PLANS = [
|
|
|
16
16
|
PRODUCTS.one
|
|
17
17
|
];
|
|
18
18
|
|
|
19
|
+
// ../license-core/src/legal-entity.ts
|
|
20
|
+
var Y_TUNNUS = /^(\d{6,7})-(\d)$/;
|
|
21
|
+
var Y_TUNNUS_WEIGHTS = [
|
|
22
|
+
7,
|
|
23
|
+
9,
|
|
24
|
+
10,
|
|
25
|
+
5,
|
|
26
|
+
8,
|
|
27
|
+
4,
|
|
28
|
+
2
|
|
29
|
+
];
|
|
30
|
+
var finnishBusinessId = /* @__PURE__ */ __name((input) => {
|
|
31
|
+
const [, body, check] = Y_TUNNUS.exec(input.trim()) ?? [];
|
|
32
|
+
if (body === void 0 || check === void 0) return null;
|
|
33
|
+
const digits = body.padStart(7, "0");
|
|
34
|
+
const remainder = Y_TUNNUS_WEIGHTS.reduce((sum, weight, index) => sum + weight * Number(digits[index]), 0) % 11;
|
|
35
|
+
const expected = remainder === 0 ? 0 : 11 - remainder;
|
|
36
|
+
return Number(check) === expected ? `${digits}-${check}` : null;
|
|
37
|
+
}, "finnishBusinessId");
|
|
38
|
+
var finnishVatId = /* @__PURE__ */ __name((businessId) => `FI${businessId.replace("-", "")}`, "finnishVatId");
|
|
39
|
+
var ANY_COUNTRY = {
|
|
40
|
+
businessId: /* @__PURE__ */ __name((input) => input.trim() || null, "businessId"),
|
|
41
|
+
vatId: /* @__PURE__ */ __name((_businessId, input) => input?.trim() || null, "vatId")
|
|
42
|
+
};
|
|
43
|
+
var COMPANY_IDS_BY_COUNTRY = {
|
|
44
|
+
FI: {
|
|
45
|
+
businessId: finnishBusinessId,
|
|
46
|
+
vatId: /* @__PURE__ */ __name((businessId, input) => {
|
|
47
|
+
const vatId = finnishVatId(businessId);
|
|
48
|
+
return input === null || input.replace(/\s/g, "").toUpperCase() === vatId ? vatId : void 0;
|
|
49
|
+
}, "vatId")
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var companyIds = /* @__PURE__ */ __name((country, input) => {
|
|
53
|
+
const rules = COMPANY_IDS_BY_COUNTRY[country.toUpperCase()] ?? ANY_COUNTRY;
|
|
54
|
+
const businessId = rules.businessId(input.businessId);
|
|
55
|
+
if (businessId === null) return {
|
|
56
|
+
invalid: "businessId"
|
|
57
|
+
};
|
|
58
|
+
const vatId = rules.vatId(businessId, input.vatId ?? null);
|
|
59
|
+
if (vatId === void 0) return {
|
|
60
|
+
invalid: "vatId"
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
businessId,
|
|
64
|
+
vatId
|
|
65
|
+
};
|
|
66
|
+
}, "companyIds");
|
|
67
|
+
|
|
19
68
|
// ../license-core/src/requestable-products.ts
|
|
20
69
|
var REQUESTABLE_PRODUCTS = [
|
|
21
70
|
"ari",
|
|
@@ -174,5 +223,8 @@ export {
|
|
|
174
223
|
PRODUCTS,
|
|
175
224
|
REQUESTABLE_PRODUCTS,
|
|
176
225
|
USAGE_METRICS,
|
|
177
|
-
USAGE_METRIC_NAMES
|
|
226
|
+
USAGE_METRIC_NAMES,
|
|
227
|
+
companyIds,
|
|
228
|
+
finnishBusinessId,
|
|
229
|
+
finnishVatId
|
|
178
230
|
};
|
package/package.json
CHANGED