feeef 0.8.5 → 0.8.9

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/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  `feeefjs` is a TypeScript library for managing feeef e-commerce platforms for self-hosted stores. It provides a wrapper for feeef rest api such like send order..., also have frontend srvices like the `CartService` class for managing cart items, shipping methods, and calculating totals. The library also includes a `NotifiableService` base class for handling listeners that react to changes in the service state.
4
4
 
5
+ ## Developer OAuth (third-party apps)
6
+
7
+ Use `OAuthRepository.buildAuthorizeUrl` (point `baseUrl` at the **accounts** host, e.g. `https://accounts.feeef.org`) and `FeeeF` client `oauth.exchangeAuthorizationCode` / `revokeToken` / `introspectToken` against the **API** base (`.../v1`). Full flow, scopes, and troubleshooting: Feeef backend **`docs/OAUTH2_DEVELOPER.md`** (in the Adonis API repo).
8
+
9
+ ## Realtime (AdonisJS Transmit)
10
+
11
+ Server-Sent Events use the same **API origin** as the REST client, but **without** the `/v1` or `/api/v1` prefix (e.g. `https://api.feeef.org/__transmit/events`). Use `createFeeefTransmit({ apiBaseUrl, getAccessToken })` so subscribe/unsubscribe POSTs get a proper `Authorization: Bearer …` header. The underlying client is the official [`@adonisjs/transmit-client`](https://www.npmjs.com/package/@adonisjs/transmit-client) (`Transmit`, `Subscription` are re-exported).
12
+
5
13
  ---
6
14
 
7
15
  # CartService & NotifiableService
package/build/index.js CHANGED
@@ -848,6 +848,9 @@ var AppRepository = class extends ModelRepository {
848
848
  * Builds the OAuth authorize URL to which the user should be redirected.
849
849
  * This is the first step of the authorization-code flow (similar UX to Google OAuth).
850
850
  *
851
+ * Production: opening this URL on the **API** host (`api.*`) issues a redirect to the same path on
852
+ * **accounts.*** so the consent screen appears on the trusted accounts domain; query params are preserved.
853
+ *
851
854
  * If the user is not logged in yet, API `GET /oauth/authorize` returns:
852
855
  * - `401 login_required`
853
856
  * - `login_url` (accounts sign-in URL with `next=...`)
@@ -880,6 +883,47 @@ var AppRepository = class extends ModelRepository {
880
883
  }
881
884
  return url.toString();
882
885
  }
886
+ /**
887
+ * Public `apps.public_data` (no auth). Pass [config] to skip Authorization if your axios instance adds it globally.
888
+ */
889
+ async getPublicData(id, config) {
890
+ const res = await this.client.get(`/${this.resource}/${id}/public-data`, config);
891
+ return res.data;
892
+ }
893
+ async getPrivateData(id) {
894
+ const res = await this.client.get(`/${this.resource}/${id}/private-data`);
895
+ return res.data;
896
+ }
897
+ async putPublicData(id, publicNamespaces) {
898
+ const res = await this.client.put(`/${this.resource}/${id}/public-data`, {
899
+ public: publicNamespaces
900
+ });
901
+ return res.data;
902
+ }
903
+ async putPrivateData(id, privateNamespaces) {
904
+ const res = await this.client.put(`/${this.resource}/${id}/private-data`, {
905
+ private: privateNamespaces
906
+ });
907
+ return res.data;
908
+ }
909
+ async getUserDataMe(id) {
910
+ const res = await this.client.get(`/${this.resource}/${id}/user-data/me`);
911
+ return res.data;
912
+ }
913
+ async putUserDataMe(id, publicNamespaces) {
914
+ const res = await this.client.put(`/${this.resource}/${id}/user-data/me`, {
915
+ public: publicNamespaces
916
+ });
917
+ return res.data;
918
+ }
919
+ async getUserDataForUser(appId, userId) {
920
+ const res = await this.client.get(`/${this.resource}/${appId}/user-data/users/${userId}`);
921
+ return res.data;
922
+ }
923
+ async putUserDataForUser(appId, userId, body) {
924
+ const res = await this.client.put(`/${this.resource}/${appId}/user-data/users/${userId}`, body);
925
+ return res.data;
926
+ }
883
927
  };
884
928
 
885
929
  // src/feeef/repositories/oauth.ts
@@ -4056,6 +4100,77 @@ var EmbaddedContactType = /* @__PURE__ */ ((EmbaddedContactType2) => {
4056
4100
  return EmbaddedContactType2;
4057
4101
  })(EmbaddedContactType || {});
4058
4102
 
4103
+ // src/realtime/transmit.ts
4104
+ import { Transmit } from "@adonisjs/transmit-client";
4105
+ import { Subscription, Transmit as Transmit2 } from "@adonisjs/transmit-client";
4106
+ function transmitRootFromApiBaseUrl(apiBaseUrl) {
4107
+ let u = apiBaseUrl.trim().replace(/\/+$/, "");
4108
+ if (u.endsWith("/api/v1")) {
4109
+ u = u.slice(0, -"/api/v1".length);
4110
+ } else if (u.endsWith("/v1")) {
4111
+ u = u.slice(0, -"/v1".length);
4112
+ }
4113
+ return u;
4114
+ }
4115
+ function retrieveXsrfTokenFromCookie() {
4116
+ const cookie = globalThis.document?.cookie;
4117
+ if (!cookie) return null;
4118
+ const match = cookie.match(new RegExp("(^|;\\s*)(XSRF-TOKEN)=([^;]*)"));
4119
+ return match ? decodeURIComponent(match[3]) : null;
4120
+ }
4121
+ var FeeefTransmitHttpClient = class {
4122
+ constructor(options, getAuthorizationHeader) {
4123
+ this.options = options;
4124
+ this.getAuthorizationHeader = getAuthorizationHeader;
4125
+ }
4126
+ send(request) {
4127
+ return fetch(request);
4128
+ }
4129
+ createRequest(path, body) {
4130
+ const headers = {
4131
+ "Content-Type": "application/json",
4132
+ "X-XSRF-TOKEN": retrieveXsrfTokenFromCookie() ?? ""
4133
+ };
4134
+ const auth = this.getAuthorizationHeader();
4135
+ if (auth) {
4136
+ headers.Authorization = auth.startsWith("Bearer ") ? auth : `Bearer ${auth}`;
4137
+ }
4138
+ return new Request(`${this.options.baseUrl}${path}`, {
4139
+ method: "POST",
4140
+ headers,
4141
+ body: JSON.stringify({ uid: this.options.uid, ...body }),
4142
+ credentials: "include"
4143
+ });
4144
+ }
4145
+ };
4146
+ function createFeeefTransmit(options) {
4147
+ const baseUrl = transmitRootFromApiBaseUrl(options.apiBaseUrl);
4148
+ const getToken = options.getAccessToken ?? (() => void 0);
4149
+ return new Transmit({
4150
+ ...options.transmit,
4151
+ baseUrl,
4152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Transmit’s HttpClient is not exported; FeeefTransmitHttpClient matches its shape.
4153
+ httpClientFactory: (url, uid) => new FeeefTransmitHttpClient({ baseUrl: url, uid }, () => {
4154
+ const t = getToken();
4155
+ if (t === null || t === void 0 || t === "") return void 0;
4156
+ const s = String(t).trim();
4157
+ return s.startsWith("Bearer ") ? s : `Bearer ${s}`;
4158
+ })
4159
+ });
4160
+ }
4161
+ function createFeeefTransmitFromAxios(client, options) {
4162
+ const apiBaseUrl = client.defaults.baseURL ?? "";
4163
+ return createFeeefTransmit({
4164
+ ...options,
4165
+ apiBaseUrl,
4166
+ getAccessToken: () => {
4167
+ const raw = client.defaults.headers.common?.Authorization;
4168
+ if (typeof raw !== "string") return void 0;
4169
+ return raw.replace(/^Bearer\s+/i, "").trim() || void 0;
4170
+ }
4171
+ });
4172
+ }
4173
+
4059
4174
  // src/utils.ts
4060
4175
  var convertDartColorToCssNumber = (dartColor) => {
4061
4176
  const alpha = dartColor >> 24 & 255;
@@ -4158,6 +4273,7 @@ export {
4158
4273
  FeedbackRepository,
4159
4274
  FeedbackStatus,
4160
4275
  FeeeF,
4276
+ FeeefTransmitHttpClient,
4161
4277
  GoogleSheetIntegrationApi,
4162
4278
  ImageGenerationsRepository,
4163
4279
  ImagePromptTemplatesRepository,
@@ -4192,8 +4308,10 @@ export {
4192
4308
  StoreRepository,
4193
4309
  StoreSubscriptionStatus,
4194
4310
  StoreSubscriptionType,
4311
+ Subscription,
4195
4312
  TiktokPixelEvent,
4196
4313
  TransferRepository,
4314
+ Transmit2 as Transmit,
4197
4315
  UserRepository,
4198
4316
  VariantOptionType,
4199
4317
  WebhookEvent,
@@ -4202,6 +4320,8 @@ export {
4202
4320
  ZimouDeliveryIntegrationApi,
4203
4321
  convertDartColorToCssNumber,
4204
4322
  convertOrderEntityToOrderTrackEntity,
4323
+ createFeeefTransmit,
4324
+ createFeeefTransmitFromAxios,
4205
4325
  createImageGenerationFormData,
4206
4326
  cssColorToHslString,
4207
4327
  dartColorToCssColor,
@@ -4237,6 +4357,7 @@ export {
4237
4357
  serializeAttachmentPayloads,
4238
4358
  serializeImagePromptTemplateCreate,
4239
4359
  serializeImagePromptTemplateUpdate,
4360
+ transmitRootFromApiBaseUrl,
4240
4361
  tryFixPhoneNumber,
4241
4362
  validatePhoneNumber
4242
4363
  };