@feedmepos/mf-miniprogram-v2 0.2.1 → 0.2.2-dev.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.
@@ -1,44 +1,45 @@
1
- import { useCoreStore as c, FeedMeAuth as v } from "@feedmepos/mf-common";
2
- import { defineComponent as h, computed as g, resolveComponent as $, openBlock as w, createElementBlock as b, createVNode as k, renderSlot as y } from "vue";
1
+ import { useCoreStore as l, FeedMeAuth as h } from "@feedmepos/mf-common";
2
+ import { defineComponent as $, computed as g, resolveComponent as w, openBlock as b, createElementBlock as k, createVNode as y, renderSlot as B } from "vue";
3
3
  import "@feedmepos/ui-library";
4
- import { useRouter as B } from "vue-router";
5
- const t = {
6
- project: (e) => `/api/projects/${e}`,
7
- provision: (e) => `/api/projects/${e}/provision`,
8
- refreshSlug: (e) => `/api/projects/${e}/refresh-slug`,
9
- sessions: (e) => `/api/projects/${e}/sessions`,
10
- session: (e, s) => `/api/projects/${e}/sessions/${s}`,
11
- messages: (e, s) => `${t.session(e, s)}/messages`,
12
- startStatus: (e, s) => `${t.session(e, s)}/start-status`,
13
- changes: (e, s, r = !1) => `${t.session(e, s)}/changes${r ? "?refresh=1" : ""}`,
14
- checkpoints: (e, s) => `${t.session(e, s)}/checkpoints`,
15
- aiBillingPreflight: (e, s) => `${t.session(e, s)}/ai-billing/preflight`,
16
- restoreCheckpoint: (e, s, r) => `${t.checkpoints(e, s)}/${r}/restore`,
17
- previewBridgeTicket: (e, s) => `${t.session(e, s)}/preview-bridge/ticket`,
18
- previewBridgeSocket: (e, s) => `${t.session(e, s)}/preview-bridge/socket`,
19
- uploads: (e, s, r = "") => `${t.session(e, s)}/uploads${r ? `?${r}` : ""}`,
20
- archive: (e, s) => `${t.session(e, s)}/archive`,
21
- commit: (e, s) => `${t.session(e, s)}/commit`,
22
- resume: (e, s) => `${t.session(e, s)}/resume`,
23
- restartPreview: (e, s) => `${t.session(e, s)}/restart-preview`,
24
- fork: (e, s) => `${t.session(e, s)}/fork`,
25
- flushEvents: (e, s) => `${t.session(e, s)}/events/flush`,
26
- revertTurn: (e, s) => `${t.session(e, s)}/turns/revert`,
27
- unrevertTurn: (e, s) => `${t.session(e, s)}/turns/unrevert`,
28
- releases: (e) => `${t.project(e)}/releases`,
29
- publishRelease: (e, s) => `${t.releases(e)}/${s}/publish`,
30
- releasePreviewUrl: (e, s) => `${t.releases(e)}/${s}/preview-url`,
31
- rollbackToRelease: (e, s) => `${t.project(e)}/rollback-to-release/${s}`,
32
- rollbackToV1: (e) => `${t.project(e)}/rollback-to-v1`,
33
- start: (e, s) => {
34
- const r = new URLSearchParams();
35
- e && r.set("businessId", e), s && r.set("sessionId", s);
36
- const n = r.toString();
37
- return `/api/start${n ? `?${n}` : ""}`;
4
+ import { useRouter as C } from "vue-router";
5
+ const c = (e, s) => `/api/businesses/${e}/projects/${s}`, t = {
6
+ portalContext: (e) => `/api/businesses/${e}/portal-context`,
7
+ project: (e, s) => c(e, s),
8
+ provision: (e, s) => `${c(e, s)}/provision`,
9
+ refreshSlug: (e, s) => `${c(e, s)}/refresh-slug`,
10
+ sessions: (e, s) => `${c(e, s)}/sessions`,
11
+ session: (e, s, r) => `${c(e, s)}/sessions/${r}`,
12
+ messages: (e, s, r) => `${t.session(e, s, r)}/messages`,
13
+ startStatus: (e, s, r) => `${t.session(e, s, r)}/start-status`,
14
+ changes: (e, s, r, n = !1) => `${t.session(e, s, r)}/changes${n ? "?refresh=1" : ""}`,
15
+ checkpoints: (e, s, r) => `${t.session(e, s, r)}/checkpoints`,
16
+ aiBillingPreflight: (e, s, r) => `${t.session(e, s, r)}/ai-billing/preflight`,
17
+ restoreCheckpoint: (e, s, r, n) => `${t.checkpoints(e, s, r)}/${n}/restore`,
18
+ previewBridgeTicket: (e, s, r) => `${t.session(e, s, r)}/preview-bridge/ticket`,
19
+ previewBridgeSocket: (e, s, r) => `${t.session(e, s, r)}/preview-bridge/socket`,
20
+ uploads: (e, s, r, n = "") => `${t.session(e, s, r)}/uploads${n ? `?${n}` : ""}`,
21
+ archive: (e, s, r) => `${t.session(e, s, r)}/archive`,
22
+ commit: (e, s, r) => `${t.session(e, s, r)}/commit`,
23
+ resume: (e, s, r) => `${t.session(e, s, r)}/resume`,
24
+ restartPreview: (e, s, r) => `${t.session(e, s, r)}/restart-preview`,
25
+ fork: (e, s, r) => `${t.session(e, s, r)}/fork`,
26
+ flushEvents: (e, s, r) => `${t.session(e, s, r)}/events/flush`,
27
+ revertTurn: (e, s, r) => `${t.session(e, s, r)}/turns/revert`,
28
+ unrevertTurn: (e, s, r) => `${t.session(e, s, r)}/turns/unrevert`,
29
+ releases: (e, s) => `${c(e, s)}/releases`,
30
+ publishRelease: (e, s, r) => `${t.releases(e, s)}/${r}/publish`,
31
+ releasePreviewUrl: (e, s, r) => `${t.releases(e, s)}/${r}/preview-url`,
32
+ rollbackToRelease: (e, s, r) => `${c(e, s)}/rollback-to-release/${r}`,
33
+ rollbackToV1: (e, s) => `${c(e, s)}/rollback-to-v1`,
34
+ start: (e, s, r) => {
35
+ const n = new URLSearchParams();
36
+ e && n.set("businessId", e), s && n.set("projectId", s), r && n.set("sessionId", r);
37
+ const i = n.toString();
38
+ return `/api/start${i ? `?${i}` : ""}`;
38
39
  },
39
40
  opencode: (e = "") => `/api/opencode${e ? `/${e.replace(/^\/+/, "")}` : ""}`,
40
- /** The shared component library's catalog. Deliberately not under
41
- * `/api/projects/:businessId`: the library belongs to no business, and the
41
+ /** The shared component library's catalog. Deliberately not under a
42
+ * business/project path: the library belongs to no business, and the
42
43
  * module centre is not inside a workspace. */
43
44
  componentLibraryCatalog: () => "/api/component-library/catalog",
44
45
  /** The self-contained preview document the module centre frames. Fetched with
@@ -47,7 +48,7 @@ const t = {
47
48
  * which is what a signed URL would otherwise exist to work around. */
48
49
  componentLibraryPreview: () => "/api/component-library/preview",
49
50
  /** The application templates this environment can provision, for the portal's
50
- * picker. Not under `/api/projects/:businessId`: the answer is a property of
51
+ * picker. Not under a business/project path: the answer is a property of
51
52
  * the environment, and it is needed BEFORE a project exists. */
52
53
  appTemplates: () => "/api/app-templates"
53
54
  }, T = [
@@ -66,15 +67,15 @@ const t = {
66
67
  "TH",
67
68
  "VN"
68
69
  ];
69
- function C(e) {
70
+ function E(e) {
70
71
  return typeof e == "string" && T.includes(e);
71
72
  }
72
73
  function U(e) {
73
74
  if (typeof e != "string") return null;
74
75
  const s = e.trim().toUpperCase();
75
- return C(s) ? s : null;
76
+ return E(s) ? s : null;
76
77
  }
77
- function E(e, s) {
78
+ function S(e, s) {
78
79
  const r = s === "MY" ? "" : `.${s.toLowerCase()}`, n = e === "dev" ? "-dev" : "", i = e === "dev" ? "https://portal.feedmedev.cc" : "https://portal.feedme.cc", o = e === "dev" ? "https://license.feedmedev.cc" : "https://license.feedme.cc";
79
80
  return {
80
81
  country: s,
@@ -85,11 +86,11 @@ function E(e, s) {
85
86
  usageUrl: `${o}/token`
86
87
  };
87
88
  }
88
- function Y(e, s, r) {
89
- const n = new URL(E(e, s).usageUrl);
89
+ function X(e, s, r) {
90
+ const n = new URL(S(e, s).usageUrl);
90
91
  return n.searchParams.set("businessId", r), n.searchParams.set("country", s), n.toString();
91
92
  }
92
- const S = "69cde0740c0106001ca83dff", P = {
93
+ const P = "69cde0740c0106001ca83dff", N = {
93
94
  dev: {
94
95
  env: "dev",
95
96
  liveDomain: "feedmedev.vip",
@@ -109,90 +110,98 @@ const S = "69cde0740c0106001ca83dff", P = {
109
110
  v1Origin: "https://brand.feedme.vip"
110
111
  }
111
112
  };
112
- function N(e) {
113
+ function _(e) {
113
114
  return e === "dev" || e === "prod";
114
115
  }
115
116
  function M(e) {
116
- if (!N(e))
117
+ if (!_(e))
117
118
  throw new Error(`MINIPROGRAM_ENV must be 'dev' or 'prod', got ${JSON.stringify(e)}`);
118
- return P[e];
119
+ return N[e];
119
120
  }
120
- function _(e) {
121
+ function x(e) {
121
122
  const s = e.toLowerCase().replace(/^fmmf:/, "");
122
123
  return s === "prod" || s === "production" ? "prod" : "dev";
123
124
  }
125
+ const D = /^[a-f0-9]{24}$/;
124
126
  function R(e) {
127
+ return D.test(e);
128
+ }
129
+ function Z(e) {
130
+ if (!R(e)) throw new Error(`Invalid business id: ${e}`);
131
+ return `prj${e}`;
132
+ }
133
+ function O(e) {
125
134
  return e.replace(/\/+$/, "");
126
135
  }
127
- function D() {
128
- return R("https://miniprogram-v2-api.feedme.vip");
136
+ function I() {
137
+ return O("https://miniprogram-v2-api.feedmedev.vip");
129
138
  }
130
- function x(e) {
131
- const s = D();
139
+ function A(e) {
140
+ const s = I();
132
141
  return s ? `${s}${e.startsWith("/") ? e : `/${e}`}` : e;
133
142
  }
134
- function l() {
135
- return c().currentBusiness.value;
143
+ function u() {
144
+ return l().currentBusiness.value;
136
145
  }
137
- function p() {
146
+ function m() {
138
147
  var e;
139
- return ((e = l()) == null ? void 0 : e._id) ?? S;
148
+ return ((e = u()) == null ? void 0 : e._id) ?? P;
140
149
  }
141
- function A() {
150
+ function L() {
142
151
  var e;
143
- return ((e = l()) == null ? void 0 : e.url) ?? void 0;
152
+ return ((e = u()) == null ? void 0 : e.url) ?? void 0;
144
153
  }
145
- function K() {
154
+ function ee() {
146
155
  var e;
147
- return ((e = l()) == null ? void 0 : e.name) ?? p();
156
+ return ((e = u()) == null ? void 0 : e.name) ?? m();
148
157
  }
149
- function j() {
150
- return c().currentCountry.value;
158
+ function F() {
159
+ return l().currentCountry.value;
151
160
  }
152
- function Q() {
161
+ function se() {
153
162
  var n;
154
- const e = (n = A()) == null ? void 0 : n.trim().toLowerCase(), s = e && /^[a-z0-9-]+$/.test(e) ? e : p(), r = M(_("fmmf:prod")).liveDomain;
163
+ const e = (n = L()) == null ? void 0 : n.trim().toLowerCase(), s = e && /^[a-z0-9-]+$/.test(e) ? e : m(), r = M(x("fmmf:dev")).liveDomain;
155
164
  return `https://${s}.${r}`;
156
165
  }
157
- function I(e) {
166
+ function j(e) {
158
167
  return new Promise((s) => window.setTimeout(s, e));
159
168
  }
160
- function X(e) {
169
+ function re(e) {
161
170
  return e instanceof Error ? e.message : String(e);
162
171
  }
163
- class L extends Error {
172
+ class q extends Error {
164
173
  constructor(s, r) {
165
174
  super(r), this.status = s, this.body = r;
166
175
  }
167
176
  }
168
- function u() {
177
+ function p() {
169
178
  var s;
170
- return ((s = c().sessionUser.value) == null ? void 0 : s.token) || v.token || "";
179
+ return ((s = l().sessionUser.value) == null ? void 0 : s.token) || h.token || "";
171
180
  }
172
- async function O() {
173
- let e = u();
181
+ async function z() {
182
+ let e = p();
174
183
  const s = Date.now() + 5e3;
175
184
  for (; !e && Date.now() < s; )
176
- await I(100), e = u();
185
+ await j(100), e = p();
177
186
  return e ? `Bearer ${e}` : null;
178
187
  }
179
- async function F(e, s = {}) {
180
- const r = new Request(e, s), n = await O();
188
+ async function V(e, s = {}) {
189
+ const r = new Request(e, s), n = await z();
181
190
  n && r.headers.set("Authorization", n);
182
- const i = U(j());
191
+ const i = U(F());
183
192
  return i && r.headers.set("x-feedme-country", i), fetch(r);
184
193
  }
185
- async function m(e, s = {}) {
194
+ async function d(e, s = {}) {
186
195
  const r = new Headers(s.headers);
187
196
  s.body && !r.has("Content-Type") && r.set("Content-Type", "application/json");
188
197
  const n = new AbortController(), i = window.setTimeout(() => n.abort(), 15e3);
189
198
  try {
190
- const o = await F(x(e), {
199
+ const o = await V(A(e), {
191
200
  ...s,
192
201
  headers: r,
193
202
  signal: s.signal ?? n.signal
194
203
  });
195
- if (!o.ok) throw new L(o.status, await o.text());
204
+ if (!o.ok) throw new q(o.status, await o.text());
196
205
  return o;
197
206
  } catch (o) {
198
207
  throw o instanceof DOMException && o.name === "AbortError" ? new Error("Control-plane request timed out") : o;
@@ -200,13 +209,13 @@ async function m(e, s = {}) {
200
209
  window.clearTimeout(i);
201
210
  }
202
211
  }
203
- async function Z(e, s = {}) {
204
- return (await m(e, s)).json();
212
+ async function ne(e, s = {}) {
213
+ return (await d(e, s)).json();
205
214
  }
206
- async function ee(e, s = {}) {
207
- return (await m(e, s)).text();
215
+ async function te(e, s = {}) {
216
+ return (await d(e, s)).text();
208
217
  }
209
- const z = { class: "flex min-w-0 shrink-0 items-center gap-12 border-b border-fm-color-neutral-gray-100 bg-fm-color-neutral-white px-16" }, V = "miniprogram-v2-module-center", se = /* @__PURE__ */ h({
218
+ const G = { class: "flex min-w-0 shrink-0 items-center gap-12 border-b border-fm-color-neutral-gray-100 bg-fm-color-neutral-white px-16" }, H = "miniprogram-v2-module-center", oe = /* @__PURE__ */ $({
210
219
  __name: "AppTabs",
211
220
  props: {
212
221
  active: {},
@@ -214,15 +223,15 @@ const z = { class: "flex min-w-0 shrink-0 items-center gap-12 border-b border-fm
214
223
  },
215
224
  emits: ["select"],
216
225
  setup(e, { emit: s }) {
217
- const r = e, n = s, i = B(), o = g(() => [
226
+ const r = e, n = s, i = C(), o = g(() => [
218
227
  { label: "Workspace", value: "workspace", icon: "space_dashboard" },
219
228
  { label: "Releases", value: "releases", icon: "rocket_launch" },
220
229
  ...r.sessionCount == null ? [{ label: "Sessions", value: "sessions", icon: "history" }] : [{ label: "Sessions", value: "sessions", icon: "history", badge: r.sessionCount }],
221
230
  { label: "Module library", value: "modules", icon: "widgets" }
222
231
  ]);
223
- function d(a) {
232
+ function f(a) {
224
233
  if (a === "modules") {
225
- i.push({ name: V });
234
+ i.push({ name: H });
226
235
  return;
227
236
  }
228
237
  if (!(a !== "workspace" && a !== "releases" && a !== "sessions")) {
@@ -236,39 +245,40 @@ const z = { class: "flex min-w-0 shrink-0 items-center gap-12 border-b border-fm
236
245
  n("select", a);
237
246
  }
238
247
  }
239
- return (a, q) => {
240
- const f = $("FmTabs");
241
- return w(), b("header", z, [
242
- k(f, {
248
+ return (a, J) => {
249
+ const v = w("FmTabs");
250
+ return b(), k("header", G, [
251
+ y(v, {
243
252
  class: "min-w-0 flex-1",
244
253
  items: o.value,
245
254
  "model-value": e.active,
246
- "onUpdate:modelValue": d
255
+ "onUpdate:modelValue": f
247
256
  }, null, 8, ["items", "model-value"]),
248
- y(a.$slots, "actions")
257
+ B(a.$slots, "actions")
249
258
  ]);
250
259
  };
251
260
  }
252
261
  });
253
262
  export {
254
- L as C,
255
- S as D,
256
- se as _,
263
+ q as C,
264
+ P as D,
265
+ oe as _,
257
266
  M as a,
258
- _ as b,
259
- p as c,
260
- F as d,
261
- X as e,
262
- x as f,
267
+ x as b,
268
+ m as c,
269
+ V as d,
270
+ re as e,
271
+ A as f,
263
272
  t as g,
264
- Z as h,
265
- O as i,
266
- A as j,
267
- j as k,
268
- K as l,
269
- Y as m,
273
+ ne as h,
274
+ z as i,
275
+ L as j,
276
+ F as k,
277
+ Z as l,
278
+ ee as m,
270
279
  U as n,
271
- Q as o,
272
- ee as p,
273
- I as s
280
+ X as o,
281
+ se as p,
282
+ te as q,
283
+ j as s
274
284
  };