@feedmepos/mf-miniprogram-v2 0.2.2-dev.0 → 0.2.2-dev.2

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.
@@ -0,0 +1,144 @@
1
+ import { a as f, e as d, D as m } from "./index-BDHUHtRw.js";
2
+ import { useCoreStore as a, FeedMeAuth as p } from "@feedmepos/mf-common";
3
+ const h = [
4
+ "AE",
5
+ "AU",
6
+ "BN",
7
+ "GB",
8
+ "ID",
9
+ "JP",
10
+ "MA",
11
+ "MO",
12
+ "MV",
13
+ "MY",
14
+ "PK",
15
+ "SG",
16
+ "TH",
17
+ "VN"
18
+ ];
19
+ function w(e) {
20
+ return typeof e == "string" && h.includes(e);
21
+ }
22
+ function g(e) {
23
+ if (typeof e != "string") return null;
24
+ const n = e.trim().toUpperCase();
25
+ return w(n) ? n : null;
26
+ }
27
+ function U(e, n) {
28
+ const t = n === "MY" ? "" : `.${n.toLowerCase()}`, r = e === "dev" ? "-dev" : "", o = e === "dev" ? "https://portal.feedmedev.cc" : "https://portal.feedme.cc", s = e === "dev" ? "https://license.feedmedev.cc" : "https://license.feedme.cc";
29
+ return {
30
+ country: n,
31
+ portalApiBaseUrl: `https://portal-v2${r}${t}.feedmeapi.com`,
32
+ licenseApiBaseUrl: `https://license-v2${r}${t}.feedmeapi.com/api`,
33
+ purchaseUrl: `${o}/purchase`,
34
+ aiTokenPurchaseUrl: `${s}/purchase`,
35
+ usageUrl: `${s}/token`
36
+ };
37
+ }
38
+ function k(e, n, t) {
39
+ const r = new URL(U(e, n).usageUrl);
40
+ return r.searchParams.set("businessId", t), r.searchParams.set("country", n), r.toString();
41
+ }
42
+ function B(e) {
43
+ return e.replace(/\/+$/, "");
44
+ }
45
+ function v() {
46
+ return B("https://miniprogram-v2-api.feedmedev.vip");
47
+ }
48
+ function y(e) {
49
+ const n = v();
50
+ return n ? `${n}${e.startsWith("/") ? e : `/${e}`}` : e;
51
+ }
52
+ function i() {
53
+ return a().currentBusiness.value;
54
+ }
55
+ function u() {
56
+ var e;
57
+ return ((e = i()) == null ? void 0 : e._id) ?? m;
58
+ }
59
+ function C() {
60
+ var e;
61
+ return ((e = i()) == null ? void 0 : e.url) ?? void 0;
62
+ }
63
+ function D() {
64
+ var e;
65
+ return ((e = i()) == null ? void 0 : e.name) ?? u();
66
+ }
67
+ function $() {
68
+ return a().currentCountry.value;
69
+ }
70
+ function x() {
71
+ var r;
72
+ const e = (r = C()) == null ? void 0 : r.trim().toLowerCase(), n = e && /^[a-z0-9-]+$/.test(e) ? e : u(), t = f(d("fmmf:dev")).liveDomain;
73
+ return `https://${n}.${t}`;
74
+ }
75
+ function S(e) {
76
+ return new Promise((n) => window.setTimeout(n, e));
77
+ }
78
+ function F(e) {
79
+ return e instanceof Error ? e.message : String(e);
80
+ }
81
+ class T extends Error {
82
+ constructor(n, t) {
83
+ super(t), this.status = n, this.body = t;
84
+ }
85
+ }
86
+ function c() {
87
+ var n;
88
+ return ((n = a().sessionUser.value) == null ? void 0 : n.token) || p.token || "";
89
+ }
90
+ async function E() {
91
+ let e = c();
92
+ const n = Date.now() + 5e3;
93
+ for (; !e && Date.now() < n; )
94
+ await S(100), e = c();
95
+ return e ? `Bearer ${e}` : null;
96
+ }
97
+ async function P(e, n = {}) {
98
+ const t = new Request(e, n), r = await E();
99
+ r && t.headers.set("Authorization", r);
100
+ const o = g($());
101
+ return o && t.headers.set("x-feedme-country", o), fetch(t);
102
+ }
103
+ async function l(e, n = {}) {
104
+ const t = new Headers(n.headers);
105
+ n.body && !t.has("Content-Type") && t.set("Content-Type", "application/json");
106
+ const r = new AbortController(), o = window.setTimeout(() => r.abort(), 15e3);
107
+ try {
108
+ const s = await P(y(e), {
109
+ ...n,
110
+ headers: t,
111
+ signal: n.signal ?? r.signal
112
+ });
113
+ if (!s.ok) throw new T(s.status, await s.text());
114
+ return s;
115
+ } catch (s) {
116
+ throw s instanceof DOMException && s.name === "AbortError" ? new Error("Control-plane request timed out") : s;
117
+ } finally {
118
+ window.clearTimeout(o);
119
+ }
120
+ }
121
+ async function b(e, n = {}) {
122
+ return (await l(e, n)).json();
123
+ }
124
+ async function I(e, n = {}) {
125
+ return (await l(e, n)).text();
126
+ }
127
+ export {
128
+ T as C,
129
+ b as a,
130
+ P as b,
131
+ x as c,
132
+ y as d,
133
+ F as e,
134
+ E as f,
135
+ u as g,
136
+ C as h,
137
+ $ as i,
138
+ D as j,
139
+ k,
140
+ i as l,
141
+ I as m,
142
+ g as n,
143
+ S as s
144
+ };
@@ -0,0 +1,46 @@
1
+ const a = "69cde0740c0106001ca83dff", i = {
2
+ dev: {
3
+ env: "dev",
4
+ liveDomain: "feedmedev.vip",
5
+ apiOrigin: "https://api.feedmedev.vip",
6
+ workerNamePrefix: "miniprogram-v2-dev",
7
+ d1DatabaseName: "miniprogram-v2-dev-metadata",
8
+ r2BucketName: "miniprogram-v2-dev-artifacts",
9
+ v1Origin: "https://brand.feedmedev.vip"
10
+ },
11
+ prod: {
12
+ env: "prod",
13
+ liveDomain: "feedme.vip",
14
+ apiOrigin: "https://api.feedme.vip",
15
+ workerNamePrefix: "miniprogram-v2-prod",
16
+ d1DatabaseName: "miniprogram-v2-prod-metadata",
17
+ r2BucketName: "miniprogram-v2-prod-artifacts",
18
+ v1Origin: "https://brand.feedme.vip"
19
+ }
20
+ };
21
+ function n(e) {
22
+ return e === "dev" || e === "prod";
23
+ }
24
+ function d(e) {
25
+ if (!n(e))
26
+ throw new Error(`MINIPROGRAM_ENV must be 'dev' or 'prod', got ${JSON.stringify(e)}`);
27
+ return i[e];
28
+ }
29
+ function m(e) {
30
+ const r = e.toLowerCase().replace(/^fmmf:/, "");
31
+ return r === "prod" || r === "production" ? "prod" : "dev";
32
+ }
33
+ const o = /^[a-f0-9]{24}$/;
34
+ function t(e) {
35
+ return o.test(e);
36
+ }
37
+ function p(e) {
38
+ if (!t(e)) throw new Error(`Invalid business id: ${e}`);
39
+ return `prj${e}`;
40
+ }
41
+ export {
42
+ a as D,
43
+ d as a,
44
+ m as e,
45
+ p as l
46
+ };
@@ -0,0 +1,34 @@
1
+ function o(t, e) {
2
+ if (typeof window > "u") return e;
3
+ try {
4
+ const r = window.localStorage.getItem(t);
5
+ return r === null ? e : r === "1";
6
+ } catch {
7
+ return e;
8
+ }
9
+ }
10
+ function i(t, e) {
11
+ if (typeof window > "u") return e;
12
+ try {
13
+ const r = Number(window.localStorage.getItem(t));
14
+ return Number.isFinite(r) ? r : e;
15
+ } catch {
16
+ return e;
17
+ }
18
+ }
19
+ function n(t, e) {
20
+ if (!(typeof window > "u"))
21
+ try {
22
+ window.localStorage.setItem(t, e);
23
+ } catch {
24
+ }
25
+ }
26
+ function u(t, e) {
27
+ n(t, e ? "1" : "0");
28
+ }
29
+ export {
30
+ i as a,
31
+ n as b,
32
+ o as r,
33
+ u as w
34
+ };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedmepos/mf-miniprogram-v2",
3
- "version": "0.2.2-dev.0",
3
+ "version": "0.2.2-dev.2",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -37,6 +37,7 @@
37
37
  "deploy:npm:prod": "pnpm run build-only:prod && pnpm run publish:npm latest"
38
38
  },
39
39
  "dependencies": {
40
+ "@casl/ability": "3.4.0",
40
41
  "@feedmepos/media-picker": "2.0.0",
41
42
  "@feedmepos/mf-common": "^1.27.9",
42
43
  "@feedmepos/ui-library": "1.8.4",
@@ -0,0 +1,47 @@
1
+ import { a as b } from "./routes-L0ady_Wy.js";
2
+ import { useCoreStore as d } from "@feedmepos/mf-common";
3
+ import { a as g, e as h } from "./controlPlane-wUT1G_Gr.js";
4
+ import { provide as y, computed as f, ref as c, watch as C, onScopeDispose as w, inject as x } from "vue";
5
+ function P() {
6
+ const e = d(), r = f(() => {
7
+ var t;
8
+ return ((t = e.currentBusiness.value) == null ? void 0 : t._id) ?? null;
9
+ }), v = f(() => {
10
+ var t;
11
+ return ((t = e.currentBusiness.value) == null ? void 0 : t.name) ?? "Your business";
12
+ }), s = c(null), a = c(!1), i = c(null);
13
+ let n = 0, o = null;
14
+ async function m() {
15
+ const t = ++n;
16
+ o == null || o.abort(), o = new AbortController();
17
+ const u = r.value;
18
+ if (i.value = null, s.value = null, a.value = !!u, !!u)
19
+ try {
20
+ const l = await g(b.portalContext(u), {
21
+ signal: AbortSignal.any([o.signal, AbortSignal.timeout(15e3)])
22
+ });
23
+ t === n && (s.value = l);
24
+ } catch (l) {
25
+ t === n && (i.value = h(l));
26
+ } finally {
27
+ t === n && (a.value = !1);
28
+ }
29
+ }
30
+ return C([r, () => e.currentCountry.value], m, { immediate: !0 }), w(() => {
31
+ n++, o == null || o.abort();
32
+ }), { businessId: r, businessName: v, context: s, loading: a, error: i, refresh: m };
33
+ }
34
+ const p = Symbol("miniprogram-portal");
35
+ function R() {
36
+ const e = P();
37
+ return y(p, e), e;
38
+ }
39
+ function j() {
40
+ const e = x(p);
41
+ if (!e) throw new Error("Portal views must be mounted inside the Miniprogram shell");
42
+ return e;
43
+ }
44
+ export {
45
+ R as p,
46
+ j as u
47
+ };
@@ -0,0 +1,28 @@
1
+ function a(r) {
2
+ return r === "releases" || r === "sessions" ? r : "workspace";
3
+ }
4
+ function o(r) {
5
+ const { view: s, ...e } = r;
6
+ return e;
7
+ }
8
+ function c(r, s, e) {
9
+ return {
10
+ name: "miniprogram-v2-project",
11
+ params: { projectId: r, view: s === "workspace" ? void 0 : s },
12
+ query: o(e)
13
+ };
14
+ }
15
+ function i(r, s = "settings") {
16
+ const e = new URLSearchParams();
17
+ for (const n of ["businessId", "country", "restaurantId"]) {
18
+ const t = r[n];
19
+ typeof t == "string" && e.set(n, t);
20
+ }
21
+ return `/brand/${s}${e.size ? `?${e}` : ""}`;
22
+ }
23
+ export {
24
+ a,
25
+ i as l,
26
+ o as p,
27
+ c as w
28
+ };
@@ -0,0 +1,53 @@
1
+ const t = (e, s) => `/api/businesses/${e}/projects/${s}`, i = {
2
+ portalContext: (e) => `/api/businesses/${e}/portal-context`,
3
+ project: (e, s) => t(e, s),
4
+ provision: (e, s) => `${t(e, s)}/provision`,
5
+ refreshSlug: (e, s) => `${t(e, s)}/refresh-slug`,
6
+ sessions: (e, s) => `${t(e, s)}/sessions`,
7
+ session: (e, s, r) => `${t(e, s)}/sessions/${r}`,
8
+ messages: (e, s, r) => `${i.session(e, s, r)}/messages`,
9
+ startStatus: (e, s, r) => `${i.session(e, s, r)}/start-status`,
10
+ changes: (e, s, r, o = !1) => `${i.session(e, s, r)}/changes${o ? "?refresh=1" : ""}`,
11
+ checkpoints: (e, s, r) => `${i.session(e, s, r)}/checkpoints`,
12
+ aiBillingPreflight: (e, s, r) => `${i.session(e, s, r)}/ai-billing/preflight`,
13
+ restoreCheckpoint: (e, s, r, o) => `${i.checkpoints(e, s, r)}/${o}/restore`,
14
+ previewBridgeTicket: (e, s, r) => `${i.session(e, s, r)}/preview-bridge/ticket`,
15
+ previewBridgeSocket: (e, s, r) => `${i.session(e, s, r)}/preview-bridge/socket`,
16
+ uploads: (e, s, r, o = "") => `${i.session(e, s, r)}/uploads${o ? `?${o}` : ""}`,
17
+ archive: (e, s, r) => `${i.session(e, s, r)}/archive`,
18
+ commit: (e, s, r) => `${i.session(e, s, r)}/commit`,
19
+ resume: (e, s, r) => `${i.session(e, s, r)}/resume`,
20
+ restartPreview: (e, s, r) => `${i.session(e, s, r)}/restart-preview`,
21
+ fork: (e, s, r) => `${i.session(e, s, r)}/fork`,
22
+ flushEvents: (e, s, r) => `${i.session(e, s, r)}/events/flush`,
23
+ revertTurn: (e, s, r) => `${i.session(e, s, r)}/turns/revert`,
24
+ unrevertTurn: (e, s, r) => `${i.session(e, s, r)}/turns/unrevert`,
25
+ releases: (e, s) => `${t(e, s)}/releases`,
26
+ publishRelease: (e, s, r) => `${i.releases(e, s)}/${r}/publish`,
27
+ releasePreviewUrl: (e, s, r) => `${i.releases(e, s)}/${r}/preview-url`,
28
+ rollbackToRelease: (e, s, r) => `${t(e, s)}/rollback-to-release/${r}`,
29
+ rollbackToV1: (e, s) => `${t(e, s)}/rollback-to-v1`,
30
+ start: (e, s, r) => {
31
+ const o = new URLSearchParams();
32
+ e && o.set("businessId", e), s && o.set("projectId", s), r && o.set("sessionId", r);
33
+ const a = o.toString();
34
+ return `/api/start${a ? `?${a}` : ""}`;
35
+ },
36
+ opencode: (e = "") => `/api/opencode${e ? `/${e.replace(/^\/+/, "")}` : ""}`,
37
+ /** The shared component library's catalog. Deliberately not under a
38
+ * business/project path: the library belongs to no business, and the
39
+ * module centre is not inside a workspace. */
40
+ componentLibraryCatalog: () => "/api/component-library/catalog",
41
+ /** The self-contained preview document the module centre frames. Fetched with
42
+ * the portal's bearer and assigned to an iframe's `srcdoc`, never used as an
43
+ * `<iframe src>` — a navigation request carries no Authorization header,
44
+ * which is what a signed URL would otherwise exist to work around. */
45
+ componentLibraryPreview: () => "/api/component-library/preview",
46
+ /** The application templates this environment can provision, for the portal's
47
+ * picker. Not under a business/project path: the answer is a property of
48
+ * the environment, and it is needed BEFORE a project exists. */
49
+ appTemplates: () => "/api/app-templates"
50
+ };
51
+ export {
52
+ i as a
53
+ };