@munchi_oy/license-sdk 0.4.0 → 0.6.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 CHANGED
@@ -31,4 +31,6 @@ const snapshot = await license.entitlements(venueId); // full snapshot, null = u
31
31
 
32
32
  Call `invalidate(venueId)` when you receive a `license.changed` event.
33
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`).
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`, `foodora`, `bolt`), with `STORE_ONLY_PRODUCTS` and `isStoreOnlyProduct` for the ones only a store asks for, never the whole group (the delivery apps).
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
@@ -25,8 +25,13 @@ __export(index_exports, {
25
25
  PLANS: () => PLANS,
26
26
  PRODUCTS: () => PRODUCTS,
27
27
  REQUESTABLE_PRODUCTS: () => REQUESTABLE_PRODUCTS,
28
+ STORE_ONLY_PRODUCTS: () => STORE_ONLY_PRODUCTS,
28
29
  USAGE_METRICS: () => USAGE_METRICS,
29
- USAGE_METRIC_NAMES: () => USAGE_METRIC_NAMES
30
+ USAGE_METRIC_NAMES: () => USAGE_METRIC_NAMES,
31
+ companyIds: () => companyIds,
32
+ finnishBusinessId: () => finnishBusinessId,
33
+ finnishVatId: () => finnishVatId,
34
+ isStoreOnlyProduct: () => isStoreOnlyProduct
30
35
  });
31
36
  module.exports = __toCommonJS(index_exports);
32
37
 
@@ -45,12 +50,69 @@ var PLANS = [
45
50
  PRODUCTS.one
46
51
  ];
47
52
 
53
+ // ../license-core/src/legal-entity.ts
54
+ var Y_TUNNUS = /^(\d{6,7})-(\d)$/;
55
+ var Y_TUNNUS_WEIGHTS = [
56
+ 7,
57
+ 9,
58
+ 10,
59
+ 5,
60
+ 8,
61
+ 4,
62
+ 2
63
+ ];
64
+ var finnishBusinessId = /* @__PURE__ */ __name((input) => {
65
+ const [, body, check] = Y_TUNNUS.exec(input.trim()) ?? [];
66
+ if (body === void 0 || check === void 0) return null;
67
+ const digits = body.padStart(7, "0");
68
+ const remainder = Y_TUNNUS_WEIGHTS.reduce((sum, weight, index) => sum + weight * Number(digits[index]), 0) % 11;
69
+ const expected = remainder === 0 ? 0 : 11 - remainder;
70
+ return Number(check) === expected ? `${digits}-${check}` : null;
71
+ }, "finnishBusinessId");
72
+ var finnishVatId = /* @__PURE__ */ __name((businessId) => `FI${businessId.replace("-", "")}`, "finnishVatId");
73
+ var ANY_COUNTRY = {
74
+ businessId: /* @__PURE__ */ __name((input) => input.trim() || null, "businessId"),
75
+ vatId: /* @__PURE__ */ __name((_businessId, input) => input?.trim() || null, "vatId")
76
+ };
77
+ var COMPANY_IDS_BY_COUNTRY = {
78
+ FI: {
79
+ businessId: finnishBusinessId,
80
+ vatId: /* @__PURE__ */ __name((businessId, input) => {
81
+ const vatId = finnishVatId(businessId);
82
+ return input === null || input.replace(/\s/g, "").toUpperCase() === vatId ? vatId : void 0;
83
+ }, "vatId")
84
+ }
85
+ };
86
+ var companyIds = /* @__PURE__ */ __name((country, input) => {
87
+ const rules = COMPANY_IDS_BY_COUNTRY[country.toUpperCase()] ?? ANY_COUNTRY;
88
+ const businessId = rules.businessId(input.businessId);
89
+ if (businessId === null) return {
90
+ invalid: "businessId"
91
+ };
92
+ const vatId = rules.vatId(businessId, input.vatId ?? null);
93
+ if (vatId === void 0) return {
94
+ invalid: "vatId"
95
+ };
96
+ return {
97
+ businessId,
98
+ vatId
99
+ };
100
+ }, "companyIds");
101
+
48
102
  // ../license-core/src/requestable-products.ts
49
103
  var REQUESTABLE_PRODUCTS = [
50
104
  "ari",
51
105
  "business_account",
52
- "capital"
106
+ "capital",
107
+ "foodora",
108
+ "bolt"
109
+ ];
110
+ var STORE_ONLY_PRODUCTS = [
111
+ "foodora",
112
+ "bolt"
53
113
  ];
114
+ var storeOnly = new Set(STORE_ONLY_PRODUCTS);
115
+ var isStoreOnlyProduct = /* @__PURE__ */ __name((product) => storeOnly.has(product), "isStoreOnlyProduct");
54
116
 
55
117
  // ../license-core/src/usage-metrics.ts
56
118
  var USAGE_METRICS = {
@@ -203,6 +265,11 @@ var LicenseClient = class {
203
265
  PLANS,
204
266
  PRODUCTS,
205
267
  REQUESTABLE_PRODUCTS,
268
+ STORE_ONLY_PRODUCTS,
206
269
  USAGE_METRICS,
207
- USAGE_METRIC_NAMES
270
+ USAGE_METRIC_NAMES,
271
+ companyIds,
272
+ finnishBusinessId,
273
+ finnishVatId,
274
+ isStoreOnlyProduct
208
275
  });
package/dist/index.d.cts CHANGED
@@ -16,13 +16,64 @@ 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
22
70
  * has its own request flow (ADR 0021). A new one is added here first.
23
71
  */
24
- declare const REQUESTABLE_PRODUCTS: readonly ["ari", "business_account", "capital"];
72
+ declare const REQUESTABLE_PRODUCTS: readonly ["ari", "business_account", "capital", "foodora", "bolt"];
25
73
  type RequestableProduct = (typeof REQUESTABLE_PRODUCTS)[number];
74
+ /** Delivery apps connect one store at a time, so only a store asks for them, never the whole group. */
75
+ declare const STORE_ONLY_PRODUCTS: readonly ["foodora", "bolt"];
76
+ declare const isStoreOnlyProduct: (product: RequestableProduct) => boolean;
26
77
 
27
78
  /**
28
79
  * What the apps report and the monthly bill can charge for: reminder SMS segments sent (added
@@ -174,4 +225,4 @@ declare class LicenseClient {
174
225
  private report;
175
226
  }
176
227
 
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 };
228
+ export { type CompanyIds, type DeniedEvent, type KnownProductCode, type LegalEntity, type LegalEntityChange, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, REQUESTABLE_PRODUCTS, type RequestableProduct, STORE_ONLY_PRODUCTS, type Snapshot, USAGE_METRICS, USAGE_METRIC_NAMES, type UsageMetric, companyIds, finnishBusinessId, finnishVatId, isStoreOnlyProduct };
package/dist/index.d.ts CHANGED
@@ -16,13 +16,64 @@ 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
22
70
  * has its own request flow (ADR 0021). A new one is added here first.
23
71
  */
24
- declare const REQUESTABLE_PRODUCTS: readonly ["ari", "business_account", "capital"];
72
+ declare const REQUESTABLE_PRODUCTS: readonly ["ari", "business_account", "capital", "foodora", "bolt"];
25
73
  type RequestableProduct = (typeof REQUESTABLE_PRODUCTS)[number];
74
+ /** Delivery apps connect one store at a time, so only a store asks for them, never the whole group. */
75
+ declare const STORE_ONLY_PRODUCTS: readonly ["foodora", "bolt"];
76
+ declare const isStoreOnlyProduct: (product: RequestableProduct) => boolean;
26
77
 
27
78
  /**
28
79
  * What the apps report and the monthly bill can charge for: reminder SMS segments sent (added
@@ -174,4 +225,4 @@ declare class LicenseClient {
174
225
  private report;
175
226
  }
176
227
 
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 };
228
+ export { type CompanyIds, type DeniedEvent, type KnownProductCode, type LegalEntity, type LegalEntityChange, LicenseClient, type LicenseClientOptions, PLANS, PRODUCTS, type PlanCode, REQUESTABLE_PRODUCTS, type RequestableProduct, STORE_ONLY_PRODUCTS, type Snapshot, USAGE_METRICS, USAGE_METRIC_NAMES, type UsageMetric, companyIds, finnishBusinessId, finnishVatId, isStoreOnlyProduct };
package/dist/index.js CHANGED
@@ -16,12 +16,69 @@ 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",
22
71
  "business_account",
23
- "capital"
72
+ "capital",
73
+ "foodora",
74
+ "bolt"
75
+ ];
76
+ var STORE_ONLY_PRODUCTS = [
77
+ "foodora",
78
+ "bolt"
24
79
  ];
80
+ var storeOnly = new Set(STORE_ONLY_PRODUCTS);
81
+ var isStoreOnlyProduct = /* @__PURE__ */ __name((product) => storeOnly.has(product), "isStoreOnlyProduct");
25
82
 
26
83
  // ../license-core/src/usage-metrics.ts
27
84
  var USAGE_METRICS = {
@@ -173,6 +230,11 @@ export {
173
230
  PLANS,
174
231
  PRODUCTS,
175
232
  REQUESTABLE_PRODUCTS,
233
+ STORE_ONLY_PRODUCTS,
176
234
  USAGE_METRICS,
177
- USAGE_METRIC_NAMES
235
+ USAGE_METRIC_NAMES,
236
+ companyIds,
237
+ finnishBusinessId,
238
+ finnishVatId,
239
+ isStoreOnlyProduct
178
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@munchi_oy/license-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Client for the Munchi license service: cached entitlements and feature checks per venue",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",