@wix/himalaya-cli 0.982.0 → 0.984.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.
Files changed (29) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/notification-preferences/src/index.d.ts +105 -33
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-notification-preferences.mjs +66 -5
  3. package/dist/cli.mjs +3437 -331
  4. package/fixtures/wix-canned.json +36 -29
  5. package/guides/sdk-reference.json +86 -49
  6. package/package.json +3 -2
  7. package/templates/beauty-salon/dev/index.ts +27 -2
  8. package/templates/beauty-salon/tier5-src/himi-branded-lite-order/index.ts +14 -6
  9. package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +59 -20
  10. package/templates/branded-lite/dev/index.ts +27 -2
  11. package/templates/branded-lite/tier5-src/himi-branded-lite-notifsettings/index.ts +42 -14
  12. package/templates/branded-lite/tier5-src/himi-branded-lite-order/index.ts +14 -6
  13. package/templates/branded-lite/tier5-src/himi-store-account/index.ts +59 -20
  14. package/templates/community-club/tier5-src/himi-store-account/index.ts +59 -20
  15. package/templates/events-meetups/tier5-src/himi-store-account/index.ts +59 -20
  16. package/templates/gym-fitness/dev/index.ts +27 -2
  17. package/templates/gym-fitness/tier5-src/himi-branded-lite-order/index.ts +14 -6
  18. package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +59 -20
  19. package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +59 -20
  20. package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +59 -20
  21. package/templates/portfolio-creative/dev/index.ts +25 -1
  22. package/templates/portfolio-creative/tier5-src/himi-branded-lite-order/index.ts +14 -6
  23. package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +59 -20
  24. package/templates/restaurant/tier5-src/himi-store-account/index.ts +59 -20
  25. package/templates/retail-store/dev/index.ts +25 -1
  26. package/templates/retail-store/tier5-src/himi-branded-lite-order/index.ts +14 -6
  27. package/templates/retail-store/tier5-src/himi-store-account/index.ts +59 -20
  28. package/templates/yoga-studio/dev/index.ts +2 -1
  29. package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +59 -20
@@ -5,56 +5,128 @@ declare global {
5
5
  };
6
6
  };
7
7
  }
8
- /** "MUTED" silences the topic on this channel; "UNMUTED" delivers it. */
8
+ /**
9
+ * The service's own mount, from the published swagger `host`
10
+ * ("www.wixapis.com/notification-preferences") — the PATH half of it.
11
+ *
12
+ * Relative, not absolute: the `wixApi` bridge supplies the gateway host. Baking one in
13
+ * works on a phone and is rejected in a browser (`400 absolute_urls_not_allowed`), so a
14
+ * client that spells the host works in one place and not the other. What was wrong
15
+ * before was the mount (`/notifications`), not the host.
16
+ */
17
+ export declare const NOTIFICATION_PREFERENCES_BASE = "/notification-preferences/v1";
18
+ /** `enum State` on `StateData`. A scalar, not an object. */
19
+ export type PreferenceState = "MUTED" | "UNMUTED" | string;
20
+ /** Kept as the name the callers already use for the value they write. */
9
21
  export type MuteStatus = "MUTED" | "UNMUTED";
10
- /** Delivery channel. The mobile push channel value is unconfirmed; "MOBILE" is
11
- * the working default the bundle passes. */
12
- export type Channel = "MOBILE" | string;
13
- export interface PreferenceState {
14
- /** "MUTED" | "UNMUTED" — whether the topic is delivered on this channel. */
15
- muteStatus?: MuteStatus;
16
- }
17
- export interface PreferenceStateData {
22
+ /** `enum Channel { UNKNOWN_CHANNEL, ALL, MOBILE, EMAIL, SMS, VOICE, BROWSER, WEB_FEED }`.
23
+ * `ALL` is real and covers mobile too — filtering it out hides preferences that do
24
+ * apply on this surface. */
25
+ export type Channel = "ALL" | "MOBILE" | "EMAIL" | "SMS" | "VOICE" | "BROWSER" | "WEB_FEED" | string;
26
+ export type RecipientType = "WIX_USER" | "CONTACT";
27
+ /** `message StateData`. `granted` and `overridden` are read-only server verdicts. */
28
+ export interface StateData {
29
+ /** The state the recipient asked for. */
18
30
  state?: PreferenceState;
31
+ /** Whether the notification is granted to be SENT. An UNMUTED topic under a muted
32
+ * channel is `granted: false` — i.e. the row must not render ON. */
33
+ granted?: boolean;
34
+ /** Whether a broader rule overrides this row, so it cannot be changed here. */
35
+ overridden?: boolean;
36
+ displayName?: string;
19
37
  }
20
- /** One topic×channel preference for the implicit recipient. */
38
+ /** `message PreferenceInfo` — one topic×channel preference. */
21
39
  export interface PreferenceInfo {
22
- /** The notification topic id (matches NotificationTopic.id). */
23
40
  topicId: string;
24
- /** Delivery channel this preference applies to (e.g. "MOBILE"). */
25
41
  channel?: Channel;
26
- stateData?: PreferenceStateData;
42
+ stateData?: StateData;
43
+ topicType?: string;
27
44
  }
45
+ /** `message NotificationPreferences`. */
28
46
  export interface NotificationPreferences {
29
47
  preferencesInfo?: PreferenceInfo[];
30
48
  }
49
+ /** `GetPreferencesBy{Implicit,}RecipientResponse` uses `notification_preferences`;
50
+ * `UpsertPreferencesBy{Implicit,}RecipientResponse` uses `preferences`. Both are
51
+ * declared so a caller cannot read the wrong one by accident. */
31
52
  export interface GetMyNotificationPreferencesResponse {
53
+ notificationPreferences?: NotificationPreferences;
54
+ }
55
+ export interface UpsertMyNotificationPreferencesResponse {
32
56
  preferences?: NotificationPreferences;
33
57
  }
34
- /** A notification topic — its id is the PreferenceInfo.topicId; displayName is
35
- * the row label shown in the UI. */
36
- export interface NotificationTopic {
37
- id: string;
58
+ /** `message NotificationTopicDefinition`. */
59
+ export interface NotificationTopicDefinition {
60
+ topicId: string;
38
61
  displayName?: string;
62
+ state?: PreferenceState;
63
+ topicType?: string;
39
64
  }
65
+ /** `GetNotificationTopicsDefinitionsResponse.preference_definitions`. */
40
66
  export interface GetNotificationTopicsResponse {
41
- topics?: NotificationTopic[];
42
- }
43
- export interface UpsertMyNotificationPreferencesRequest {
44
- preferencesInfo: PreferenceInfo[];
67
+ preferenceDefinitions?: NotificationTopicDefinition[];
45
68
  }
46
- export interface UpsertMyNotificationPreferencesResponse {
47
- preferences?: NotificationPreferences;
48
- }
49
- /** Map a UI "on" boolean to a MuteStatus: on ⇒ delivered ("UNMUTED"). */
69
+ /** The topic list, or empty when the response carried none. */
70
+ export declare function readTopics(res: GetNotificationTopicsResponse | undefined): NotificationTopicDefinition[];
71
+ /** The preference rows out of EITHER response shape (see the asymmetry note above). */
72
+ export declare function readPreferences(res: GetMyNotificationPreferencesResponse | UpsertMyNotificationPreferencesResponse | undefined): PreferenceInfo[];
73
+ /** Map a UI "on" boolean to the state to WRITE: on ⇒ delivered ("UNMUTED"). */
50
74
  export declare function muteStatusFor(on: boolean): MuteStatus;
51
- /** Get the signed-in member's notification preferences —
52
- * GET /notifications/v1/preferences-by-implicit-recipient. */
53
- export declare function getMyNotificationPreferences(): Promise<GetMyNotificationPreferencesResponse>;
54
- /** List the available notification topics (id + displayName for labels) —
55
- * GET /notifications/v1/preferences/topics. */
75
+ /**
76
+ * Whether this row is actually being delivered right now.
77
+ *
78
+ * `granted` is the server's verdict and beats `state`: a topic the recipient unmuted
79
+ * under a channel they muted is `state: "UNMUTED", granted: false`. Rendering `state`
80
+ * alone shows ON for a notification that will never arrive.
81
+ */
82
+ export declare function isDeliveredNow(stateData: StateData | undefined): boolean;
83
+ /** Whether a broader rule overrides this row, so the UI must not offer to change it. */
84
+ export declare function isLocked(stateData: StateData | undefined): boolean;
85
+ /**
86
+ * The one preference row that governs `topicId` on `channel`, or undefined when the
87
+ * recipient has no row for it (⇒ the topic's default, which is delivery).
88
+ *
89
+ * A topic can carry SEVERAL rows — one per channel, plus a channel-wide `ALL` — and
90
+ * the response order is not specified. Picking with a bare `find` therefore rendered
91
+ * whichever row the service happened to list first, so a mobile switch could show an
92
+ * EMAIL preference, and a MOBILE + ALL pair flipped meaning between two identical
93
+ * reads. Resolved by SPECIFICITY instead: the exact channel wins, then `ALL`, then a
94
+ * row that names no channel at all.
95
+ */
96
+ export declare function preferenceFor(topicId: string, prefs: readonly PreferenceInfo[], channel?: Channel): PreferenceInfo | undefined;
97
+ /**
98
+ * Per-topic "is this actually being delivered on `channel`" verdicts.
99
+ *
100
+ * A topic with no row is absent from the map, not false: absent means "the topic's
101
+ * own default", which the caller renders as ON.
102
+ */
103
+ export declare function deliveredByTopic(prefs: readonly PreferenceInfo[], channel?: Channel): Record<string, boolean>;
104
+ /** List the site's notification topics — `GET /v1/preferences/topics`
105
+ * (GetNotificationTopicsDefinitions). Publicly mounted.
106
+ * verify-live: source contract checked; live caller authorization remains untested. */
56
107
  export declare function getNotificationTopics(): Promise<GetNotificationTopicsResponse>;
57
- /** Upsert one or more of the signed-in member's preferences —
58
- * POST /notifications/v1/preferences-by-implicit-recipient, body
59
- * { preferencesInfo }. Pass only the rows that changed. */
108
+ /**
109
+ * The PUBLICLY mounted preferences read — `GET /v1/preferences`
110
+ * (GetPreferencesByRecipient). It needs the recipient explicitly: `CONTACT` + a
111
+ * contactId for a member, `WIX_USER` + a wixUserId for an owner.
112
+ *
113
+ * Prefer this from an app going through the public gateway; the implicit-recipient
114
+ * variant below is not among the five paths the swagger exposes.
115
+ * verify-live: source contract checked; live caller authorization remains untested.
116
+ */
117
+ export declare function getPreferencesForRecipient(recipient: {
118
+ recipientType: RecipientType;
119
+ contactId?: string;
120
+ wixUserId?: string;
121
+ language?: string;
122
+ }): Promise<GetMyNotificationPreferencesResponse>;
123
+ /** The signed-in recipient's preferences — `GET /v1/preferences-by-implicit-recipient`
124
+ * (GetPreferencesByImplicitRecipient). NOT in the published public swagger; a 404 from
125
+ * the public gateway is the expected outcome there, not a bug in this call.
126
+ * verify-live: the implicit-recipient mount has not been verified for member callers. */
127
+ export declare function getMyNotificationPreferences(): Promise<GetMyNotificationPreferencesResponse>;
128
+ /** Upsert some of the signed-in recipient's preferences —
129
+ * `POST /v1/preferences-by-implicit-recipient` (UpsertPreferencesByImplicitRecipient),
130
+ * body `{ preferencesInfo }`. Pass only the rows that changed.
131
+ * verify-live: the implicit-recipient mount has not been verified for member callers. */
60
132
  export declare function upsertMyNotificationPreferences(preferencesInfo: PreferenceInfo[]): Promise<UpsertMyNotificationPreferencesResponse>;
@@ -5,27 +5,88 @@ function wixCall(method, path, body, headers) {
5
5
  }
6
6
  return globalThis.himalaya.wixApi.call(method, path, body, headers);
7
7
  }
8
- var BASE = "/notifications/v1";
8
+ var NOTIFICATION_PREFERENCES_BASE = "/notification-preferences/v1";
9
+ function readTopics(res) {
10
+ return res?.preferenceDefinitions ?? [];
11
+ }
12
+ function readPreferences(res) {
13
+ const container = res?.notificationPreferences ?? res?.preferences;
14
+ return container?.preferencesInfo ?? [];
15
+ }
9
16
  function muteStatusFor(on) {
10
17
  return on ? "UNMUTED" : "MUTED";
11
18
  }
12
- function getMyNotificationPreferences() {
13
- return wixCall("GET", `${BASE}/preferences-by-implicit-recipient`);
19
+ function isDeliveredNow(stateData) {
20
+ if (!stateData) return false;
21
+ if (typeof stateData.granted === "boolean") return stateData.granted;
22
+ return stateData.state === "UNMUTED";
23
+ }
24
+ function isLocked(stateData) {
25
+ return stateData?.overridden === true;
26
+ }
27
+ function preferenceFor(topicId, prefs, channel = "MOBILE") {
28
+ let allRow;
29
+ let unscoped;
30
+ for (const p of prefs) {
31
+ if (p.topicId !== topicId) continue;
32
+ if (p.channel === channel) return p;
33
+ if (p.channel === "ALL") allRow ?? (allRow = p);
34
+ else if (!p.channel) unscoped ?? (unscoped = p);
35
+ }
36
+ return allRow ?? unscoped;
37
+ }
38
+ function deliveredByTopic(prefs, channel = "MOBILE") {
39
+ const out = {};
40
+ for (const p of prefs) {
41
+ if (!p.topicId || p.topicId in out) continue;
42
+ const governing = preferenceFor(p.topicId, prefs, channel);
43
+ if (governing) out[p.topicId] = isDeliveredNow(governing.stateData);
44
+ }
45
+ return out;
14
46
  }
15
47
  function getNotificationTopics() {
16
- return wixCall("GET", `${BASE}/preferences/topics`);
48
+ return wixCall(
49
+ "GET",
50
+ `${NOTIFICATION_PREFERENCES_BASE}/preferences/topics`
51
+ );
52
+ }
53
+ function getPreferencesForRecipient(recipient) {
54
+ const query = Object.entries({
55
+ recipientType: recipient.recipientType,
56
+ contactId: recipient.contactId,
57
+ wixUserId: recipient.wixUserId,
58
+ language: recipient.language
59
+ }).filter(([, value]) => Boolean(value)).map(([key, value]) => `${key}=${encodeURIComponent(value ?? "")}`).join("&");
60
+ return wixCall(
61
+ "GET",
62
+ `${NOTIFICATION_PREFERENCES_BASE}/preferences?${query}`
63
+ );
64
+ }
65
+ function getMyNotificationPreferences() {
66
+ return wixCall(
67
+ "GET",
68
+ `${NOTIFICATION_PREFERENCES_BASE}/preferences-by-implicit-recipient`
69
+ );
17
70
  }
18
71
  function upsertMyNotificationPreferences(preferencesInfo) {
19
72
  return wixCall(
20
73
  "POST",
21
- `${BASE}/preferences-by-implicit-recipient`,
74
+ `${NOTIFICATION_PREFERENCES_BASE}/preferences-by-implicit-recipient`,
22
75
  { preferencesInfo }
23
76
  );
24
77
  }
25
78
  export {
79
+ NOTIFICATION_PREFERENCES_BASE,
80
+ deliveredByTopic,
26
81
  getMyNotificationPreferences,
27
82
  getNotificationTopics,
83
+ getPreferencesForRecipient,
84
+ isDeliveredNow,
85
+ isLocked,
28
86
  muteStatusFor,
87
+ preferenceFor,
88
+ readPreferences,
89
+ readTopics,
29
90
  upsertMyNotificationPreferences
30
91
  };
31
92
  //# sourceMappingURL=wix-notification-preferences.mjs.map