@munchi_oy/license-sdk 0.3.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 +4 -0
- package/dist/index.cjs +66 -2
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +61 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,3 +30,7 @@ const snapshot = await license.entitlements(venueId); // full snapshot, null = u
|
|
|
30
30
|
| `mode: "enforce"` | `can()` returns `false` for features the venue doesn't have, or while it is suspended |
|
|
31
31
|
|
|
32
32
|
Call `invalidate(venueId)` when you receive a `license.changed` event.
|
|
33
|
+
|
|
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
|
@@ -24,8 +24,12 @@ __export(index_exports, {
|
|
|
24
24
|
LicenseClient: () => LicenseClient,
|
|
25
25
|
PLANS: () => PLANS,
|
|
26
26
|
PRODUCTS: () => PRODUCTS,
|
|
27
|
+
REQUESTABLE_PRODUCTS: () => REQUESTABLE_PRODUCTS,
|
|
27
28
|
USAGE_METRICS: () => USAGE_METRICS,
|
|
28
|
-
USAGE_METRIC_NAMES: () => USAGE_METRIC_NAMES
|
|
29
|
+
USAGE_METRIC_NAMES: () => USAGE_METRIC_NAMES,
|
|
30
|
+
companyIds: () => companyIds,
|
|
31
|
+
finnishBusinessId: () => finnishBusinessId,
|
|
32
|
+
finnishVatId: () => finnishVatId
|
|
29
33
|
});
|
|
30
34
|
module.exports = __toCommonJS(index_exports);
|
|
31
35
|
|
|
@@ -44,6 +48,62 @@ var PLANS = [
|
|
|
44
48
|
PRODUCTS.one
|
|
45
49
|
];
|
|
46
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
|
+
|
|
100
|
+
// ../license-core/src/requestable-products.ts
|
|
101
|
+
var REQUESTABLE_PRODUCTS = [
|
|
102
|
+
"ari",
|
|
103
|
+
"business_account",
|
|
104
|
+
"capital"
|
|
105
|
+
];
|
|
106
|
+
|
|
47
107
|
// ../license-core/src/usage-metrics.ts
|
|
48
108
|
var USAGE_METRICS = {
|
|
49
109
|
sms: "sum",
|
|
@@ -194,6 +254,10 @@ var LicenseClient = class {
|
|
|
194
254
|
LicenseClient,
|
|
195
255
|
PLANS,
|
|
196
256
|
PRODUCTS,
|
|
257
|
+
REQUESTABLE_PRODUCTS,
|
|
197
258
|
USAGE_METRICS,
|
|
198
|
-
USAGE_METRIC_NAMES
|
|
259
|
+
USAGE_METRIC_NAMES,
|
|
260
|
+
companyIds,
|
|
261
|
+
finnishBusinessId,
|
|
262
|
+
finnishVatId
|
|
199
263
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,62 @@ 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
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Products a store asks Munchi for in the dashboard because they can't be bought online
|
|
69
|
+
* (ADR 0022). These are the dashboard's product ids, not catalog codes (`MUN-*`); the mobile app
|
|
70
|
+
* has its own request flow (ADR 0021). A new one is added here first.
|
|
71
|
+
*/
|
|
72
|
+
declare const REQUESTABLE_PRODUCTS: readonly ["ari", "business_account", "capital"];
|
|
73
|
+
type RequestableProduct = (typeof REQUESTABLE_PRODUCTS)[number];
|
|
74
|
+
|
|
19
75
|
/**
|
|
20
76
|
* What the apps report and the monthly bill can charge for: reminder SMS segments sent (added
|
|
21
77
|
* up), and loyalty members (the month's highest count, since Start includes 150 and each one
|
|
@@ -166,4 +222,4 @@ declare class LicenseClient {
|
|
|
166
222
|
private report;
|
|
167
223
|
}
|
|
168
224
|
|
|
169
|
-
export { type DeniedEvent, type KnownProductCode, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, 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,62 @@ 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
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Products a store asks Munchi for in the dashboard because they can't be bought online
|
|
69
|
+
* (ADR 0022). These are the dashboard's product ids, not catalog codes (`MUN-*`); the mobile app
|
|
70
|
+
* has its own request flow (ADR 0021). A new one is added here first.
|
|
71
|
+
*/
|
|
72
|
+
declare const REQUESTABLE_PRODUCTS: readonly ["ari", "business_account", "capital"];
|
|
73
|
+
type RequestableProduct = (typeof REQUESTABLE_PRODUCTS)[number];
|
|
74
|
+
|
|
19
75
|
/**
|
|
20
76
|
* What the apps report and the monthly bill can charge for: reminder SMS segments sent (added
|
|
21
77
|
* up), and loyalty members (the month's highest count, since Start includes 150 and each one
|
|
@@ -166,4 +222,4 @@ declare class LicenseClient {
|
|
|
166
222
|
private report;
|
|
167
223
|
}
|
|
168
224
|
|
|
169
|
-
export { type DeniedEvent, type KnownProductCode, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, 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,62 @@ 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
|
+
|
|
68
|
+
// ../license-core/src/requestable-products.ts
|
|
69
|
+
var REQUESTABLE_PRODUCTS = [
|
|
70
|
+
"ari",
|
|
71
|
+
"business_account",
|
|
72
|
+
"capital"
|
|
73
|
+
];
|
|
74
|
+
|
|
19
75
|
// ../license-core/src/usage-metrics.ts
|
|
20
76
|
var USAGE_METRICS = {
|
|
21
77
|
sms: "sum",
|
|
@@ -165,6 +221,10 @@ export {
|
|
|
165
221
|
LicenseClient,
|
|
166
222
|
PLANS,
|
|
167
223
|
PRODUCTS,
|
|
224
|
+
REQUESTABLE_PRODUCTS,
|
|
168
225
|
USAGE_METRICS,
|
|
169
|
-
USAGE_METRIC_NAMES
|
|
226
|
+
USAGE_METRIC_NAMES,
|
|
227
|
+
companyIds,
|
|
228
|
+
finnishBusinessId,
|
|
229
|
+
finnishVatId
|
|
170
230
|
};
|
package/package.json
CHANGED