@wix/himalaya-cli 0.1852.0 → 0.1853.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/dist/cli.mjs +95 -32
- package/guides/himi-json-output.md +8 -2
- package/guides/one-app-section-mappings.md +1 -1
- package/guides/one-app-to-himi-app.md +19 -6
- package/package.json +2 -2
- package/template-icons/bare-fashion.png +0 -0
- package/templates/bare-fashion/README.md +52 -0
- package/templates/bare-fashion/config.ts +474 -0
- package/templates/bare-fashion/dev/index.ts +16526 -0
- package/templates/bare-fashion/himalaya.content.json +70 -0
- package/templates/bare-fashion/himalaya.template.json +18 -0
- package/templates/bare-fashion/icon.png +0 -0
- package/templates/bare-fashion/platforms.json +3 -0
- package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
- package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
- package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
- package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
- package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
- package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
- package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
- package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
- package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
- package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
- package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
- package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
- package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
- package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
- package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
- package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
- package/templates/bare-fashion/tokens.json +348 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
- package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
- package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
- package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
- package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
- package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
- package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
- package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
- package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__HIMI_APP_NAME__",
|
|
3
|
+
"screens": {
|
|
4
|
+
"himi_account": {
|
|
5
|
+
"displayName": "Account"
|
|
6
|
+
},
|
|
7
|
+
"himi_address_form": {
|
|
8
|
+
"displayName": "Address Form"
|
|
9
|
+
},
|
|
10
|
+
"himi_addresses": {
|
|
11
|
+
"displayName": "Addresses"
|
|
12
|
+
},
|
|
13
|
+
"himi_app_info": {
|
|
14
|
+
"displayName": "App Info"
|
|
15
|
+
},
|
|
16
|
+
"himi_appearance": {
|
|
17
|
+
"displayName": "Appearance"
|
|
18
|
+
},
|
|
19
|
+
"himi_branded_home": {
|
|
20
|
+
"displayName": "Home"
|
|
21
|
+
},
|
|
22
|
+
"himi_cart": {
|
|
23
|
+
"displayName": "Cart"
|
|
24
|
+
},
|
|
25
|
+
"himi_collection": {
|
|
26
|
+
"displayName": "Collection"
|
|
27
|
+
},
|
|
28
|
+
"himi_collections": {
|
|
29
|
+
"displayName": "Collections"
|
|
30
|
+
},
|
|
31
|
+
"himi_delete_account": {
|
|
32
|
+
"displayName": "Delete Account"
|
|
33
|
+
},
|
|
34
|
+
"himi_help": {
|
|
35
|
+
"displayName": "Help"
|
|
36
|
+
},
|
|
37
|
+
"himi_order": {
|
|
38
|
+
"displayName": "Order"
|
|
39
|
+
},
|
|
40
|
+
"himi_orders": {
|
|
41
|
+
"displayName": "Orders"
|
|
42
|
+
},
|
|
43
|
+
"himi_product": {
|
|
44
|
+
"displayName": "Product Details"
|
|
45
|
+
},
|
|
46
|
+
"himi_products": {
|
|
47
|
+
"displayName": "Products"
|
|
48
|
+
},
|
|
49
|
+
"himi_saved_products": {
|
|
50
|
+
"displayName": "Favorites"
|
|
51
|
+
},
|
|
52
|
+
"himi_search": {
|
|
53
|
+
"displayName": "Search"
|
|
54
|
+
},
|
|
55
|
+
"himi_shop": {
|
|
56
|
+
"displayName": "Shop"
|
|
57
|
+
},
|
|
58
|
+
"himi_sign_in": {
|
|
59
|
+
"displayName": "Sign In"
|
|
60
|
+
},
|
|
61
|
+
"himi_view_profile": {
|
|
62
|
+
"displayName": "View Profile"
|
|
63
|
+
},
|
|
64
|
+
"himi_wallet": {
|
|
65
|
+
"displayName": "Wallet"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"icon": "icon.png",
|
|
69
|
+
"target": "prod"
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "BARE Fashion Store",
|
|
3
|
+
"description": "A mobile storefront for fashion, apparel and accessories brands on Wix Stores: new arrivals and clothing collections by category, product details with sizes and colours, favorites, a cart with Wix checkout, orders, and the brand's story and policies. Black-and-white editorial design. Boots as a visitor; members sign in for orders and saved addresses.",
|
|
4
|
+
"tags": [
|
|
5
|
+
"fashion",
|
|
6
|
+
"apparel",
|
|
7
|
+
"clothing",
|
|
8
|
+
"retail",
|
|
9
|
+
"storefront",
|
|
10
|
+
"wix",
|
|
11
|
+
"consumer",
|
|
12
|
+
"vertical:fashion",
|
|
13
|
+
"stores",
|
|
14
|
+
"cart",
|
|
15
|
+
"orders"
|
|
16
|
+
],
|
|
17
|
+
"category": "shopping"
|
|
18
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The language a worker formats numbers, money and plurals in, and the business's time zone. A worker has no host locale to read,
|
|
2
|
+
// so the screen's `onAppear` hands it over: `appear()` adds `locale` to the load params when the app
|
|
3
|
+
// pins its language, and `stashCopy` stores it here. Absent, every formatter stays on "en" — the
|
|
4
|
+
// house pattern every English app was approved with — so an unpinned app is unchanged.
|
|
5
|
+
//
|
|
6
|
+
// The business time zone comes the same way, from the app's provisioning (`businessTimeZone`, collected
|
|
7
|
+
// at migration time while the site's properties are readable): a worker cannot read it itself, because
|
|
8
|
+
// the site-properties route is owner-scoped. Absent, it is "" and no worker guesses one.
|
|
9
|
+
//
|
|
10
|
+
// Pure, no host globals: bundled into every worker that formats, copied into generated templates.
|
|
11
|
+
|
|
12
|
+
const TAG = /^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
|
|
13
|
+
let tag = "en";
|
|
14
|
+
|
|
15
|
+
/** Set from a load argument's `locale`; anything that is not a language tag resets to "en". */
|
|
16
|
+
export function setAppLocale(value: unknown): void {
|
|
17
|
+
tag = typeof value === "string" && TAG.test(value) ? value : "en";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function appLocale(): string {
|
|
21
|
+
return tag;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** An IANA zone such as "Asia/Jerusalem" (or "UTC") that this engine knows. A bare offset, a lowercase
|
|
25
|
+
* alias or an engine without ECMA-402 is not one: a zone is never guessed. */
|
|
26
|
+
export function isIanaTimeZone(value: unknown): value is string {
|
|
27
|
+
if (typeof value !== "string" || !/^(?:UTC|[A-Za-z]+(?:\/[A-Za-z0-9_+-]+)+)$/.test(value)) return false;
|
|
28
|
+
// An engine without ECMA-402 has no zone database: nothing it holds is a zone it knows.
|
|
29
|
+
if (typeof Intl === "object" && typeof Intl.DateTimeFormat === "function") {
|
|
30
|
+
try {
|
|
31
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
32
|
+
return true;
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let zone = "";
|
|
41
|
+
|
|
42
|
+
/** Set from a load argument's `businessTimeZone`; anything that is not an IANA zone clears it. */
|
|
43
|
+
export function setBusinessTimeZone(value: unknown): void {
|
|
44
|
+
zone = isIanaTimeZone(value) ? value : "";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The business's IANA zone, or "" when the app has none provisioned. */
|
|
48
|
+
export function businessTimeZone(): string {
|
|
49
|
+
return zone;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Does `count` take the singular form in the app language? CLDR plural rules, so French "0 point"
|
|
53
|
+
* and "1,5 point" are singular and Hebrew "2" is not. An engine without PluralRules keeps the
|
|
54
|
+
* English rule (exactly one). */
|
|
55
|
+
export function isSingular(count: number, locale = appLocale()): boolean {
|
|
56
|
+
try {
|
|
57
|
+
// An engine without ECMA-402 has no `Intl` at all: it keeps the English rule.
|
|
58
|
+
if (typeof Intl === "object" && typeof Intl.PluralRules === "function") return new Intl.PluralRules(locale).select(count) === "one";
|
|
59
|
+
} catch { /* malformed tag — use the English rule */ }
|
|
60
|
+
return count === 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The CLDR plural category of `count` in the app language (`zero`, `one`, `two`, `few`, `many` or `other`). An engine
|
|
64
|
+
* without PluralRules keeps the English rule: `one` for exactly one, else `other`. */
|
|
65
|
+
export function pluralCategory(count: number, locale = appLocale()): string {
|
|
66
|
+
try {
|
|
67
|
+
if (typeof Intl === "object" && typeof Intl.PluralRules === "function") return new Intl.PluralRules(locale).select(count);
|
|
68
|
+
} catch { /* malformed tag — use the English rule */ }
|
|
69
|
+
return count === 1 ? "one" : "other";
|
|
70
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// The signed-in member's address book: the Wix Addresses service (wix.addresses.api.v1).
|
|
2
|
+
// The site's My Addresses page and Wix checkout use the same service, so an address saved
|
|
3
|
+
// in the app shows on the site and in checkout. No generated SDK client covers it, so the
|
|
4
|
+
// calls go through the raw `wixCall` transport with the member's session.
|
|
5
|
+
//
|
|
6
|
+
// Workers cannot message each other. The form screen bumps one on-device row after a save,
|
|
7
|
+
// and the list screen polls that row (a local read, no network) to know when to reload.
|
|
8
|
+
import { wixCall } from "@himalaya/wix-ecom";
|
|
9
|
+
import { getAll, upsert, type DbEntity } from "@himalaya/local-db";
|
|
10
|
+
import { COUNTRIES, type CountryRow } from "./bare-fashion-address-countries.js";
|
|
11
|
+
|
|
12
|
+
const BASE = "/addresses-web/api/v1/addresses";
|
|
13
|
+
|
|
14
|
+
export interface WixAddress {
|
|
15
|
+
id?: string | null;
|
|
16
|
+
fullName?: { firstName?: string; lastName?: string };
|
|
17
|
+
/** ISO 3166 alpha-3 ("IRL"). Read code also accepts alpha-2. */
|
|
18
|
+
country?: string | null;
|
|
19
|
+
/** Region key with no country prefix ("NY"). */
|
|
20
|
+
subdivision?: string | null;
|
|
21
|
+
city?: string | null;
|
|
22
|
+
zipCode?: string | null;
|
|
23
|
+
phoneNumber?: string | null;
|
|
24
|
+
company?: string | null;
|
|
25
|
+
email?: string | null;
|
|
26
|
+
addressLine1?: string | null;
|
|
27
|
+
addressLine2?: string | null;
|
|
28
|
+
street?: { name?: string; number?: string; apt?: string | null };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AddressList {
|
|
32
|
+
addresses: WixAddress[];
|
|
33
|
+
defaultAddressId: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function listAddresses(): Promise<AddressList> {
|
|
37
|
+
const res = await wixCall<{ addresses?: WixAddress[]; defaultAddressId?: string }>("GET", BASE);
|
|
38
|
+
return { addresses: (res?.addresses ?? []).filter((a) => !!a.id), defaultAddressId: res?.defaultAddressId ?? "" };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function getAddress(id: string): Promise<{ address?: WixAddress; isDefault: boolean }> {
|
|
42
|
+
const res = await wixCall<{ address?: WixAddress; isDefaultAddress?: boolean }>("GET", `${BASE}/${encodeURIComponent(id)}`);
|
|
43
|
+
return { address: res?.address, isDefault: res?.isDefaultAddress === true };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Wix makes the first address the default, whatever `setAsDefault` says. */
|
|
47
|
+
export async function createAddress(address: WixAddress, setAsDefault: boolean): Promise<string> {
|
|
48
|
+
const res = await wixCall<{ id?: string }>("POST", BASE, { address, setAsDefault });
|
|
49
|
+
return res?.id ?? "";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function updateAddress(address: WixAddress, fieldMask: string[], setAsDefault: boolean): Promise<void> {
|
|
53
|
+
await wixCall("PATCH", `${BASE}/${encodeURIComponent(String(address.id))}`, { address, fieldMask, setAsDefault });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function deleteAddress(id: string): Promise<void> {
|
|
57
|
+
await wixCall("DELETE", `${BASE}/${encodeURIComponent(id)}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function setDefaultAddress(id: string): Promise<void> {
|
|
61
|
+
await wixCall("POST", `${BASE}/default`, { id });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── Change signal ─────────────────────────────────────────────────────────────────────
|
|
65
|
+
const SIGNAL_ENTITY = "address_book";
|
|
66
|
+
const SIGNAL_ROW = "rev";
|
|
67
|
+
|
|
68
|
+
export async function bumpAddressBook(): Promise<void> {
|
|
69
|
+
try { await upsert(SIGNAL_ENTITY, { id: SIGNAL_ROW, rev: String(Date.now()) } as unknown as DbEntity); } catch { /* local_database not granted */ }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function readAddressBookRev(): Promise<string> {
|
|
73
|
+
try {
|
|
74
|
+
const rows = (await getAll(SIGNAL_ENTITY)) as unknown as { id: string; rev?: string }[];
|
|
75
|
+
return rows.find((r) => r.id === SIGNAL_ROW)?.rev ?? "";
|
|
76
|
+
} catch {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ── Countries and display ─────────────────────────────────────────────────────────────
|
|
82
|
+
export function countryByCode(code: string | null | undefined): CountryRow | undefined {
|
|
83
|
+
const c = String(code ?? "").trim().toUpperCase();
|
|
84
|
+
if (!c) return undefined;
|
|
85
|
+
return COUNTRIES.find((row) => row[0] === c) ?? COUNTRIES.find((row) => row[1] === c);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function regionName(country: CountryRow | undefined, key: string | null | undefined): string {
|
|
89
|
+
const k = String(key ?? "").trim();
|
|
90
|
+
if (!k) return "";
|
|
91
|
+
const bare = k.includes("-") ? k.slice(k.indexOf("-") + 1) : k;
|
|
92
|
+
return country?.[6].find(([rk]) => rk === bare)?.[1] ?? bare;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function fullNameOf(a: WixAddress): string {
|
|
96
|
+
return [a.fullName?.firstName, a.fullName?.lastName].map((p) => (p ?? "").trim()).filter(Boolean).join(" ");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The street line. Some countries store street name and number instead of line 1. */
|
|
100
|
+
export function streetLineOf(a: WixAddress): string {
|
|
101
|
+
const line1 = (a.addressLine1 ?? "").trim();
|
|
102
|
+
if (line1) return line1;
|
|
103
|
+
return [a.street?.name, a.street?.number].map((p) => (p ?? "").trim()).filter(Boolean).join(" ");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** "Dublin, Dublin D02 X285" — city, then region and postal code. */
|
|
107
|
+
export function cityLineOf(a: WixAddress): string {
|
|
108
|
+
const country = countryByCode(a.country);
|
|
109
|
+
const region = regionName(country, a.subdivision);
|
|
110
|
+
const tail = [region, (a.zipCode ?? "").trim()].filter(Boolean).join(" ");
|
|
111
|
+
return [(a.city ?? "").trim(), tail].filter(Boolean).join(", ");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function countryNameOf(a: WixAddress): string {
|
|
115
|
+
return countryByCode(a.country)?.[2] ?? String(a.country ?? "");
|
|
116
|
+
}
|