@stardeck-customer-apps/controls 0.3.0 → 0.4.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/SKILL.md +59 -6
- package/dist/index.cjs +36 -1
- package/dist/index.d.cts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.js +35 -1
- package/dist/server/index.cjs +34 -1
- package/dist/server/index.d.cts +20 -0
- package/dist/server/index.d.ts +20 -0
- package/dist/server/index.js +34 -1
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
Controls are values Stardeck owns and your app reads while it runs: feature
|
|
6
6
|
flags, what the plan allows, how many locations have POS Pro hardware, which
|
|
7
|
-
Accounting edition the business pays for,
|
|
8
|
-
the app uses
|
|
7
|
+
Accounting edition the business pays for, which payment provider and methods
|
|
8
|
+
the app uses, and who the business is (its name, address, tax ID, currency and
|
|
9
|
+
time zone). Your app asks Stardeck about once a minute and keeps the answer in memory.
|
|
9
10
|
A change on Stardeck reaches the app within about a minute, with no deploy.
|
|
10
11
|
|
|
11
12
|
Never invent controls or flags of your own. The list is fixed by Stardeck and
|
|
@@ -53,6 +54,7 @@ the last values stay.
|
|
|
53
54
|
| `plan.accountingEdition` | `"small" \| "medium" \| null` | no |
|
|
54
55
|
| `payments.provider` | `"beam" \| "stripe" \| null` | yes |
|
|
55
56
|
| `payments.methods` | `{ card: boolean, promptPay: boolean }` | yes |
|
|
57
|
+
| `business.profile` | `BusinessProfile \| null` (see "Business details") | yes |
|
|
56
58
|
|
|
57
59
|
- `plan.locations.included` is what the plan covers. `max` is a hard cap (the
|
|
58
60
|
entry plan has 1); `null` means no cap, and each location past `included` is
|
|
@@ -63,6 +65,9 @@ the last values stay.
|
|
|
63
65
|
- `plan.accountingEdition` is the Accounting edition the business pays for, an
|
|
64
66
|
add-on next to its plan. `null` means it has no Accounting plan. See
|
|
65
67
|
"Accounting edition" below.
|
|
68
|
+
- `business.profile` is the business the app is for, as Stardeck keeps it for
|
|
69
|
+
the organization. `null` means Stardeck has no record yet. See "Business
|
|
70
|
+
details" below.
|
|
66
71
|
- Keys are never removed in later versions, so code written against today's list
|
|
67
72
|
keeps working.
|
|
68
73
|
|
|
@@ -116,6 +121,53 @@ if (edition.value === null) {
|
|
|
116
121
|
// edition.value is "small" or "medium"
|
|
117
122
|
```
|
|
118
123
|
|
|
124
|
+
## Business details
|
|
125
|
+
|
|
126
|
+
Stardeck keeps one business record per organization: what the owner told
|
|
127
|
+
Stardeck when they signed up, edited in Stardeck's Business settings. Every app
|
|
128
|
+
in the organization reads the same record (needs controls 0.4.0 or later):
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
type BusinessProfile = {
|
|
132
|
+
kind: string; // a business preset id: "restaurant", "spa", "general"…
|
|
133
|
+
name: { en: string; th: string | null };
|
|
134
|
+
headOfficeAddress: string | null;
|
|
135
|
+
taxId: string | null;
|
|
136
|
+
country: string; // ISO 3166-1 alpha-2, "TH"
|
|
137
|
+
currency: string; // ISO 4217, "THB"
|
|
138
|
+
timezone: string; // IANA, "Asia/Bangkok"
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Stardeck owns it; the app keeps a copy. Mirror it into the app's own records
|
|
143
|
+
(the default company, the currency and time zone settings, the business preset)
|
|
144
|
+
whenever the value differs from what the app holds:
|
|
145
|
+
|
|
146
|
+
- `{ ok: true, value }`: copy `value` into the app. A `kind` this app does not
|
|
147
|
+
have stays on the general preset; never fail on it.
|
|
148
|
+
- `{ ok: true, value: null }`: Stardeck has no record yet. If the app already
|
|
149
|
+
has its own company details, send them up once with `setControl`; otherwise
|
|
150
|
+
ask the owner as before.
|
|
151
|
+
- `ok: false`: unknown right now, which is not the same as `null`. Change
|
|
152
|
+
nothing and keep the company the app has. Never blank a name or address
|
|
153
|
+
because of `ok: false`.
|
|
154
|
+
|
|
155
|
+
When the owner edits the business inside the app, write it to Stardeck first
|
|
156
|
+
with `setControl("business.profile", profile, { userToken })`, then save the
|
|
157
|
+
app's own copy from the answer. Saving only the app's copy would be undone by
|
|
158
|
+
the next mirror. Only an admin of the organization on Stardeck may write it, so
|
|
159
|
+
a `FORBIDDEN` answer means "ask an organization admin"; show `error.message`.
|
|
160
|
+
`null` is refused (`INVALID_VALUE`): the app can change the details but not
|
|
161
|
+
remove them. Validate input with the same rules Stardeck uses:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import { businessProfileSchema } from "@stardeck-customer-apps/controls";
|
|
165
|
+
|
|
166
|
+
const parsed = businessProfileSchema.safeParse(input);
|
|
167
|
+
if (!parsed.success) return badRequest(parsed.error.issues[0]?.message);
|
|
168
|
+
const result = await setControl("business.profile", parsed.data, { userToken });
|
|
169
|
+
```
|
|
170
|
+
|
|
119
171
|
Types and the list itself are in the root export:
|
|
120
172
|
|
|
121
173
|
```ts
|
|
@@ -124,10 +176,11 @@ import { CONTROLS, parseControls, type ControlKey } from "@stardeck-customer-app
|
|
|
124
176
|
|
|
125
177
|
## Changing provider or methods
|
|
126
178
|
|
|
127
|
-
Only `payments.provider` and `
|
|
128
|
-
only on behalf of a signed-in person. Pass that
|
|
129
|
-
checks that this person may change the app's
|
|
130
|
-
|
|
179
|
+
Only `payments.provider`, `payments.methods` and `business.profile` can be
|
|
180
|
+
changed from the app, and only on behalf of a signed-in person. Pass that
|
|
181
|
+
person's session token. Stardeck checks that this person may change the app's
|
|
182
|
+
settings (for `business.profile`, that they are an admin of the organization);
|
|
183
|
+
the app's own roles are never enough.
|
|
131
184
|
|
|
132
185
|
```ts
|
|
133
186
|
import { cookies } from "next/headers";
|
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CONTROLS: () => CONTROLS,
|
|
24
24
|
CONTROL_KEYS: () => CONTROL_KEYS,
|
|
25
|
+
businessProfileSchema: () => businessProfileSchema,
|
|
25
26
|
isControlKey: () => isControlKey,
|
|
26
27
|
isWritableControl: () => isWritableControl,
|
|
27
28
|
parseControls: () => parseControls,
|
|
@@ -31,6 +32,33 @@ module.exports = __toCommonJS(index_exports);
|
|
|
31
32
|
|
|
32
33
|
// src/controls.ts
|
|
33
34
|
var import_zod = require("zod");
|
|
35
|
+
function isIanaTimeZone(value) {
|
|
36
|
+
try {
|
|
37
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var businessProfileSchema = import_zod.z.object({
|
|
44
|
+
/** The kind of business: a business preset id the app defines (`restaurant`, `spa`, `general`…). */
|
|
45
|
+
kind: import_zod.z.string().regex(/^[a-z][a-z0-9-]{0,39}$/, "a business kind is a lowercase preset id"),
|
|
46
|
+
/** The company's name. Thai is null when the business has no Thai name. */
|
|
47
|
+
name: import_zod.z.object({
|
|
48
|
+
en: import_zod.z.string().trim().min(1, "the business needs a name").max(200),
|
|
49
|
+
th: import_zod.z.string().trim().min(1).max(200).nullable()
|
|
50
|
+
}),
|
|
51
|
+
/** Head-office address as one block of text; null until someone enters it. */
|
|
52
|
+
headOfficeAddress: import_zod.z.string().trim().min(1).max(1e3).nullable(),
|
|
53
|
+
/** Tax ID; null for a business with none (under the VAT threshold, say). */
|
|
54
|
+
taxId: import_zod.z.string().trim().min(1).max(40).nullable(),
|
|
55
|
+
/** ISO 3166-1 alpha-2. */
|
|
56
|
+
country: import_zod.z.string().regex(/^[A-Z]{2}$/, "country is an ISO 3166-1 alpha-2 code"),
|
|
57
|
+
/** ISO 4217. */
|
|
58
|
+
currency: import_zod.z.string().regex(/^[A-Z]{3}$/, "currency is an ISO 4217 code"),
|
|
59
|
+
/** IANA time zone. */
|
|
60
|
+
timezone: import_zod.z.string().refine(isIanaTimeZone, "timezone is not an IANA time zone")
|
|
61
|
+
});
|
|
34
62
|
var CONTROLS = {
|
|
35
63
|
"flag.paymentsSetupStep": { schema: import_zod.z.boolean(), appWrite: false },
|
|
36
64
|
"plan.locations": {
|
|
@@ -68,7 +96,13 @@ var CONTROLS = {
|
|
|
68
96
|
"plan.accountingEdition": {
|
|
69
97
|
schema: import_zod.z.enum(["small", "medium"]).nullable(),
|
|
70
98
|
appWrite: false
|
|
71
|
-
}
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
102
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
103
|
+
* unknown right now: keep the company the app has.
|
|
104
|
+
*/
|
|
105
|
+
"business.profile": { schema: businessProfileSchema.nullable(), appWrite: true }
|
|
72
106
|
};
|
|
73
107
|
var CONTROL_KEYS = Object.keys(CONTROLS);
|
|
74
108
|
function isControlKey(key) {
|
|
@@ -114,6 +148,7 @@ function unavailableControls(reason) {
|
|
|
114
148
|
0 && (module.exports = {
|
|
115
149
|
CONTROLS,
|
|
116
150
|
CONTROL_KEYS,
|
|
151
|
+
businessProfileSchema,
|
|
117
152
|
isControlKey,
|
|
118
153
|
isWritableControl,
|
|
119
154
|
parseControls,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Who the business is, as Stardeck keeps it for the org: what onboarding asks and Stardeck's
|
|
5
|
+
* Business settings edit. The app mirrors it into its default company and workspace settings, and
|
|
6
|
+
* sends an owner's edit back through this same control, so Stardeck stays the one source.
|
|
7
|
+
*/
|
|
8
|
+
declare const businessProfileSchema: z.ZodObject<{
|
|
9
|
+
kind: z.ZodString;
|
|
10
|
+
name: z.ZodObject<{
|
|
11
|
+
en: z.ZodString;
|
|
12
|
+
th: z.ZodNullable<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
headOfficeAddress: z.ZodNullable<z.ZodString>;
|
|
15
|
+
taxId: z.ZodNullable<z.ZodString>;
|
|
16
|
+
country: z.ZodString;
|
|
17
|
+
currency: z.ZodString;
|
|
18
|
+
timezone: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
type BusinessProfile = z.infer<typeof businessProfileSchema>;
|
|
3
21
|
/**
|
|
4
22
|
* The controls list: every value the platform owns and an app reads.
|
|
5
23
|
*
|
|
@@ -66,6 +84,26 @@ declare const CONTROLS: {
|
|
|
66
84
|
}>>;
|
|
67
85
|
readonly appWrite: false;
|
|
68
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
89
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
90
|
+
* unknown right now: keep the company the app has.
|
|
91
|
+
*/
|
|
92
|
+
readonly "business.profile": {
|
|
93
|
+
readonly schema: z.ZodNullable<z.ZodObject<{
|
|
94
|
+
kind: z.ZodString;
|
|
95
|
+
name: z.ZodObject<{
|
|
96
|
+
en: z.ZodString;
|
|
97
|
+
th: z.ZodNullable<z.ZodString>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
headOfficeAddress: z.ZodNullable<z.ZodString>;
|
|
100
|
+
taxId: z.ZodNullable<z.ZodString>;
|
|
101
|
+
country: z.ZodString;
|
|
102
|
+
currency: z.ZodString;
|
|
103
|
+
timezone: z.ZodString;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
readonly appWrite: true;
|
|
106
|
+
};
|
|
69
107
|
};
|
|
70
108
|
type ControlKey = keyof typeof CONTROLS;
|
|
71
109
|
type ControlValue<K extends ControlKey> = z.infer<(typeof CONTROLS)[K]["schema"]>;
|
|
@@ -118,4 +156,4 @@ declare function parseControls(raw: unknown): Controls;
|
|
|
118
156
|
/** Every control unavailable for one reason (cold start with the platform down, or not configured). */
|
|
119
157
|
declare function unavailableControls(reason: string): Controls;
|
|
120
158
|
|
|
121
|
-
export { CONTROLS, CONTROL_KEYS, type ControlKey, type ControlResult, type ControlValue, type ControlWriteError, type ControlWriteErrorCode, type ControlWriteRequest, type Controls, type ControlsSyncRequest, type ControlsSyncResponse, type ControlsUsage, type WritableControlKey, isControlKey, isWritableControl, parseControls, unavailableControls };
|
|
159
|
+
export { type BusinessProfile, CONTROLS, CONTROL_KEYS, type ControlKey, type ControlResult, type ControlValue, type ControlWriteError, type ControlWriteErrorCode, type ControlWriteRequest, type Controls, type ControlsSyncRequest, type ControlsSyncResponse, type ControlsUsage, type WritableControlKey, businessProfileSchema, isControlKey, isWritableControl, parseControls, unavailableControls };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Who the business is, as Stardeck keeps it for the org: what onboarding asks and Stardeck's
|
|
5
|
+
* Business settings edit. The app mirrors it into its default company and workspace settings, and
|
|
6
|
+
* sends an owner's edit back through this same control, so Stardeck stays the one source.
|
|
7
|
+
*/
|
|
8
|
+
declare const businessProfileSchema: z.ZodObject<{
|
|
9
|
+
kind: z.ZodString;
|
|
10
|
+
name: z.ZodObject<{
|
|
11
|
+
en: z.ZodString;
|
|
12
|
+
th: z.ZodNullable<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
headOfficeAddress: z.ZodNullable<z.ZodString>;
|
|
15
|
+
taxId: z.ZodNullable<z.ZodString>;
|
|
16
|
+
country: z.ZodString;
|
|
17
|
+
currency: z.ZodString;
|
|
18
|
+
timezone: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
type BusinessProfile = z.infer<typeof businessProfileSchema>;
|
|
3
21
|
/**
|
|
4
22
|
* The controls list: every value the platform owns and an app reads.
|
|
5
23
|
*
|
|
@@ -66,6 +84,26 @@ declare const CONTROLS: {
|
|
|
66
84
|
}>>;
|
|
67
85
|
readonly appWrite: false;
|
|
68
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
89
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
90
|
+
* unknown right now: keep the company the app has.
|
|
91
|
+
*/
|
|
92
|
+
readonly "business.profile": {
|
|
93
|
+
readonly schema: z.ZodNullable<z.ZodObject<{
|
|
94
|
+
kind: z.ZodString;
|
|
95
|
+
name: z.ZodObject<{
|
|
96
|
+
en: z.ZodString;
|
|
97
|
+
th: z.ZodNullable<z.ZodString>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
headOfficeAddress: z.ZodNullable<z.ZodString>;
|
|
100
|
+
taxId: z.ZodNullable<z.ZodString>;
|
|
101
|
+
country: z.ZodString;
|
|
102
|
+
currency: z.ZodString;
|
|
103
|
+
timezone: z.ZodString;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
readonly appWrite: true;
|
|
106
|
+
};
|
|
69
107
|
};
|
|
70
108
|
type ControlKey = keyof typeof CONTROLS;
|
|
71
109
|
type ControlValue<K extends ControlKey> = z.infer<(typeof CONTROLS)[K]["schema"]>;
|
|
@@ -118,4 +156,4 @@ declare function parseControls(raw: unknown): Controls;
|
|
|
118
156
|
/** Every control unavailable for one reason (cold start with the platform down, or not configured). */
|
|
119
157
|
declare function unavailableControls(reason: string): Controls;
|
|
120
158
|
|
|
121
|
-
export { CONTROLS, CONTROL_KEYS, type ControlKey, type ControlResult, type ControlValue, type ControlWriteError, type ControlWriteErrorCode, type ControlWriteRequest, type Controls, type ControlsSyncRequest, type ControlsSyncResponse, type ControlsUsage, type WritableControlKey, isControlKey, isWritableControl, parseControls, unavailableControls };
|
|
159
|
+
export { type BusinessProfile, CONTROLS, CONTROL_KEYS, type ControlKey, type ControlResult, type ControlValue, type ControlWriteError, type ControlWriteErrorCode, type ControlWriteRequest, type Controls, type ControlsSyncRequest, type ControlsSyncResponse, type ControlsUsage, type WritableControlKey, businessProfileSchema, isControlKey, isWritableControl, parseControls, unavailableControls };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
// src/controls.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
function isIanaTimeZone(value) {
|
|
4
|
+
try {
|
|
5
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
6
|
+
return true;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
var businessProfileSchema = z.object({
|
|
12
|
+
/** The kind of business: a business preset id the app defines (`restaurant`, `spa`, `general`…). */
|
|
13
|
+
kind: z.string().regex(/^[a-z][a-z0-9-]{0,39}$/, "a business kind is a lowercase preset id"),
|
|
14
|
+
/** The company's name. Thai is null when the business has no Thai name. */
|
|
15
|
+
name: z.object({
|
|
16
|
+
en: z.string().trim().min(1, "the business needs a name").max(200),
|
|
17
|
+
th: z.string().trim().min(1).max(200).nullable()
|
|
18
|
+
}),
|
|
19
|
+
/** Head-office address as one block of text; null until someone enters it. */
|
|
20
|
+
headOfficeAddress: z.string().trim().min(1).max(1e3).nullable(),
|
|
21
|
+
/** Tax ID; null for a business with none (under the VAT threshold, say). */
|
|
22
|
+
taxId: z.string().trim().min(1).max(40).nullable(),
|
|
23
|
+
/** ISO 3166-1 alpha-2. */
|
|
24
|
+
country: z.string().regex(/^[A-Z]{2}$/, "country is an ISO 3166-1 alpha-2 code"),
|
|
25
|
+
/** ISO 4217. */
|
|
26
|
+
currency: z.string().regex(/^[A-Z]{3}$/, "currency is an ISO 4217 code"),
|
|
27
|
+
/** IANA time zone. */
|
|
28
|
+
timezone: z.string().refine(isIanaTimeZone, "timezone is not an IANA time zone")
|
|
29
|
+
});
|
|
3
30
|
var CONTROLS = {
|
|
4
31
|
"flag.paymentsSetupStep": { schema: z.boolean(), appWrite: false },
|
|
5
32
|
"plan.locations": {
|
|
@@ -37,7 +64,13 @@ var CONTROLS = {
|
|
|
37
64
|
"plan.accountingEdition": {
|
|
38
65
|
schema: z.enum(["small", "medium"]).nullable(),
|
|
39
66
|
appWrite: false
|
|
40
|
-
}
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
70
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
71
|
+
* unknown right now: keep the company the app has.
|
|
72
|
+
*/
|
|
73
|
+
"business.profile": { schema: businessProfileSchema.nullable(), appWrite: true }
|
|
41
74
|
};
|
|
42
75
|
var CONTROL_KEYS = Object.keys(CONTROLS);
|
|
43
76
|
function isControlKey(key) {
|
|
@@ -82,6 +115,7 @@ function unavailableControls(reason) {
|
|
|
82
115
|
export {
|
|
83
116
|
CONTROLS,
|
|
84
117
|
CONTROL_KEYS,
|
|
118
|
+
businessProfileSchema,
|
|
85
119
|
isControlKey,
|
|
86
120
|
isWritableControl,
|
|
87
121
|
parseControls,
|
package/dist/server/index.cjs
CHANGED
|
@@ -32,6 +32,33 @@ module.exports = __toCommonJS(index_exports);
|
|
|
32
32
|
|
|
33
33
|
// src/controls.ts
|
|
34
34
|
var import_zod = require("zod");
|
|
35
|
+
function isIanaTimeZone(value) {
|
|
36
|
+
try {
|
|
37
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var businessProfileSchema = import_zod.z.object({
|
|
44
|
+
/** The kind of business: a business preset id the app defines (`restaurant`, `spa`, `general`…). */
|
|
45
|
+
kind: import_zod.z.string().regex(/^[a-z][a-z0-9-]{0,39}$/, "a business kind is a lowercase preset id"),
|
|
46
|
+
/** The company's name. Thai is null when the business has no Thai name. */
|
|
47
|
+
name: import_zod.z.object({
|
|
48
|
+
en: import_zod.z.string().trim().min(1, "the business needs a name").max(200),
|
|
49
|
+
th: import_zod.z.string().trim().min(1).max(200).nullable()
|
|
50
|
+
}),
|
|
51
|
+
/** Head-office address as one block of text; null until someone enters it. */
|
|
52
|
+
headOfficeAddress: import_zod.z.string().trim().min(1).max(1e3).nullable(),
|
|
53
|
+
/** Tax ID; null for a business with none (under the VAT threshold, say). */
|
|
54
|
+
taxId: import_zod.z.string().trim().min(1).max(40).nullable(),
|
|
55
|
+
/** ISO 3166-1 alpha-2. */
|
|
56
|
+
country: import_zod.z.string().regex(/^[A-Z]{2}$/, "country is an ISO 3166-1 alpha-2 code"),
|
|
57
|
+
/** ISO 4217. */
|
|
58
|
+
currency: import_zod.z.string().regex(/^[A-Z]{3}$/, "currency is an ISO 4217 code"),
|
|
59
|
+
/** IANA time zone. */
|
|
60
|
+
timezone: import_zod.z.string().refine(isIanaTimeZone, "timezone is not an IANA time zone")
|
|
61
|
+
});
|
|
35
62
|
var CONTROLS = {
|
|
36
63
|
"flag.paymentsSetupStep": { schema: import_zod.z.boolean(), appWrite: false },
|
|
37
64
|
"plan.locations": {
|
|
@@ -69,7 +96,13 @@ var CONTROLS = {
|
|
|
69
96
|
"plan.accountingEdition": {
|
|
70
97
|
schema: import_zod.z.enum(["small", "medium"]).nullable(),
|
|
71
98
|
appWrite: false
|
|
72
|
-
}
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
102
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
103
|
+
* unknown right now: keep the company the app has.
|
|
104
|
+
*/
|
|
105
|
+
"business.profile": { schema: businessProfileSchema.nullable(), appWrite: true }
|
|
73
106
|
};
|
|
74
107
|
var CONTROL_KEYS = Object.keys(CONTROLS);
|
|
75
108
|
function parseOne(entry, schema) {
|
package/dist/server/index.d.cts
CHANGED
|
@@ -66,6 +66,26 @@ declare const CONTROLS: {
|
|
|
66
66
|
}>>;
|
|
67
67
|
readonly appWrite: false;
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
71
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
72
|
+
* unknown right now: keep the company the app has.
|
|
73
|
+
*/
|
|
74
|
+
readonly "business.profile": {
|
|
75
|
+
readonly schema: z.ZodNullable<z.ZodObject<{
|
|
76
|
+
kind: z.ZodString;
|
|
77
|
+
name: z.ZodObject<{
|
|
78
|
+
en: z.ZodString;
|
|
79
|
+
th: z.ZodNullable<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
headOfficeAddress: z.ZodNullable<z.ZodString>;
|
|
82
|
+
taxId: z.ZodNullable<z.ZodString>;
|
|
83
|
+
country: z.ZodString;
|
|
84
|
+
currency: z.ZodString;
|
|
85
|
+
timezone: z.ZodString;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
readonly appWrite: true;
|
|
88
|
+
};
|
|
69
89
|
};
|
|
70
90
|
type ControlKey = keyof typeof CONTROLS;
|
|
71
91
|
type ControlValue<K extends ControlKey> = z.infer<(typeof CONTROLS)[K]["schema"]>;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -66,6 +66,26 @@ declare const CONTROLS: {
|
|
|
66
66
|
}>>;
|
|
67
67
|
readonly appWrite: false;
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
71
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
72
|
+
* unknown right now: keep the company the app has.
|
|
73
|
+
*/
|
|
74
|
+
readonly "business.profile": {
|
|
75
|
+
readonly schema: z.ZodNullable<z.ZodObject<{
|
|
76
|
+
kind: z.ZodString;
|
|
77
|
+
name: z.ZodObject<{
|
|
78
|
+
en: z.ZodString;
|
|
79
|
+
th: z.ZodNullable<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
headOfficeAddress: z.ZodNullable<z.ZodString>;
|
|
82
|
+
taxId: z.ZodNullable<z.ZodString>;
|
|
83
|
+
country: z.ZodString;
|
|
84
|
+
currency: z.ZodString;
|
|
85
|
+
timezone: z.ZodString;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
readonly appWrite: true;
|
|
88
|
+
};
|
|
69
89
|
};
|
|
70
90
|
type ControlKey = keyof typeof CONTROLS;
|
|
71
91
|
type ControlValue<K extends ControlKey> = z.infer<(typeof CONTROLS)[K]["schema"]>;
|
package/dist/server/index.js
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
// src/controls.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
function isIanaTimeZone(value) {
|
|
4
|
+
try {
|
|
5
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
6
|
+
return true;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
var businessProfileSchema = z.object({
|
|
12
|
+
/** The kind of business: a business preset id the app defines (`restaurant`, `spa`, `general`…). */
|
|
13
|
+
kind: z.string().regex(/^[a-z][a-z0-9-]{0,39}$/, "a business kind is a lowercase preset id"),
|
|
14
|
+
/** The company's name. Thai is null when the business has no Thai name. */
|
|
15
|
+
name: z.object({
|
|
16
|
+
en: z.string().trim().min(1, "the business needs a name").max(200),
|
|
17
|
+
th: z.string().trim().min(1).max(200).nullable()
|
|
18
|
+
}),
|
|
19
|
+
/** Head-office address as one block of text; null until someone enters it. */
|
|
20
|
+
headOfficeAddress: z.string().trim().min(1).max(1e3).nullable(),
|
|
21
|
+
/** Tax ID; null for a business with none (under the VAT threshold, say). */
|
|
22
|
+
taxId: z.string().trim().min(1).max(40).nullable(),
|
|
23
|
+
/** ISO 3166-1 alpha-2. */
|
|
24
|
+
country: z.string().regex(/^[A-Z]{2}$/, "country is an ISO 3166-1 alpha-2 code"),
|
|
25
|
+
/** ISO 4217. */
|
|
26
|
+
currency: z.string().regex(/^[A-Z]{3}$/, "currency is an ISO 4217 code"),
|
|
27
|
+
/** IANA time zone. */
|
|
28
|
+
timezone: z.string().refine(isIanaTimeZone, "timezone is not an IANA time zone")
|
|
29
|
+
});
|
|
3
30
|
var CONTROLS = {
|
|
4
31
|
"flag.paymentsSetupStep": { schema: z.boolean(), appWrite: false },
|
|
5
32
|
"plan.locations": {
|
|
@@ -37,7 +64,13 @@ var CONTROLS = {
|
|
|
37
64
|
"plan.accountingEdition": {
|
|
38
65
|
schema: z.enum(["small", "medium"]).nullable(),
|
|
39
66
|
appWrite: false
|
|
40
|
-
}
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* The business this app is for, owned by Stardeck. null means Stardeck has no record yet: an
|
|
70
|
+
* app that already has its own company details sends them up once. `{ ok: false }` means
|
|
71
|
+
* unknown right now: keep the company the app has.
|
|
72
|
+
*/
|
|
73
|
+
"business.profile": { schema: businessProfileSchema.nullable(), appWrite: true }
|
|
41
74
|
};
|
|
42
75
|
var CONTROL_KEYS = Object.keys(CONTROLS);
|
|
43
76
|
function parseOne(entry, schema) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stardeck-customer-apps/controls",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "Platform-owned app controls (feature flags, plan limits, POS Pro hardware, the Accounting edition, payment provider and methods) for Stardeck customer apps: a typed list plus a cached, signed sync client",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|