@flowrunner/cli 0.1.14 → 0.1.15

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 (43) hide show
  1. package/ai-docs/instructions/service-code-format/04-http-requests.md +9 -0
  2. package/ai-docs/instructions/service-code-format/06-oauth2.md +59 -9
  3. package/ai-docs/instructions/service-code-format/07-actions.md +1 -1
  4. package/ai-docs/instructions/service-code-format/08-polling-triggers.md +13 -0
  5. package/ai-docs/instructions/service-code-format/09-realtime-triggers.md +110 -4
  6. package/ai-docs/instructions/service-code-format/16-gotchas.md +24 -0
  7. package/ai-docs/instructions/service-code-format/18-test-recipes.md +16 -0
  8. package/ai-docs/instructions/service-code-format/19-security.md +121 -0
  9. package/ai-docs/instructions/service-code-format/README.md +3 -2
  10. package/ai-docs/providers/claude/agents/flowrunner-service-code-engineer.md +1 -1
  11. package/dist/cli.js +48 -9
  12. package/dist/cli.js.map +2 -2
  13. package/dist/index.js +47 -8
  14. package/dist/index.js.map +2 -2
  15. package/dist/types/flow-extension-runner/src/v2/oauth/types.d.ts +9 -7
  16. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +2 -1
  17. package/dist/types/shared/src/constants/activity-log.d.ts +77 -0
  18. package/dist/types/shared/src/constants/app.d.ts +0 -1
  19. package/dist/types/shared/src/constants/notification-types.d.ts +117 -6
  20. package/dist/types/shared/src/scheme/account/dto.d.ts +3 -0
  21. package/dist/types/shared/src/scheme/crm/dto.d.ts +6 -0
  22. package/dist/types/shared/src/scheme/index.d.ts +1 -0
  23. package/dist/types/shared/src/scheme/integration-connection/dto.d.ts +27 -15
  24. package/dist/types/shared/src/scheme/notifications/dto.d.ts +3 -0
  25. package/dist/types/shared/src/scheme/notifications/rest.d.ts +6 -0
  26. package/dist/types/shared/src/scheme/onboarding/dto.d.ts +29 -0
  27. package/dist/types/shared/src/scheme/onboarding/index.d.ts +1 -0
  28. package/package.json +1 -1
  29. package/runtime/index.js +47 -8
  30. package/runtime/index.js.map +2 -2
  31. package/runtime/types/flow-extension-runner/src/v2/oauth/types.d.ts +9 -7
  32. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +2 -1
  33. package/runtime/types/shared/src/constants/activity-log.d.ts +77 -0
  34. package/runtime/types/shared/src/constants/app.d.ts +0 -1
  35. package/runtime/types/shared/src/constants/notification-types.d.ts +117 -6
  36. package/runtime/types/shared/src/scheme/account/dto.d.ts +3 -0
  37. package/runtime/types/shared/src/scheme/crm/dto.d.ts +6 -0
  38. package/runtime/types/shared/src/scheme/index.d.ts +1 -0
  39. package/runtime/types/shared/src/scheme/integration-connection/dto.d.ts +27 -15
  40. package/runtime/types/shared/src/scheme/notifications/dto.d.ts +3 -0
  41. package/runtime/types/shared/src/scheme/notifications/rest.d.ts +6 -0
  42. package/runtime/types/shared/src/scheme/onboarding/dto.d.ts +29 -0
  43. package/runtime/types/shared/src/scheme/onboarding/index.d.ts +1 -0
package/dist/cli.js CHANGED
@@ -14508,7 +14508,7 @@ var require_package = __commonJS({
14508
14508
  "package.json"(exports2, module2) {
14509
14509
  module2.exports = {
14510
14510
  name: "@flowrunner/cli",
14511
- version: "0.1.14",
14511
+ version: "0.1.15",
14512
14512
  publishConfig: {
14513
14513
  access: "public"
14514
14514
  },
@@ -18221,10 +18221,11 @@ var OAuth2 = class {
18221
18221
  this.#registerSystemMethods();
18222
18222
  }
18223
18223
  // The handler bag's `oauth`: the header access token, plus its deserialized composite payload when the
18224
- // author declared a deserializer (the pattern for providers whose "token" carries a realm or instance id).
18224
+ // author declared a deserializer (the pattern for providers whose "token" carries a realm or instance id),
18225
+ // and that payload's `userData` — the standard shape's slot for per-connection data.
18225
18226
  buildBag(accessToken) {
18226
18227
  const token = this.props.deserializeToken && accessToken != null ? this.props.deserializeToken(accessToken) : void 0;
18227
- return { accessToken, token };
18228
+ return { accessToken, token, userData: userDataOf(token) };
18228
18229
  }
18229
18230
  // ── SYSTEM seam: name · input · return · handler, in one table ─────────────
18230
18231
  #registerSystemMethods() {
@@ -18312,12 +18313,23 @@ var OAuth2 = class {
18312
18313
  });
18313
18314
  const nextRefresh = tokenResponse.refresh_token ?? currentRefreshToken;
18314
18315
  return {
18315
- token: this.#serialize(tokenResponse.access_token, nextRefresh),
18316
+ token: this.#serialize(tokenResponse.access_token, nextRefresh, this.#storedUserData(ctx)),
18316
18317
  expirationInSeconds: tokenResponse.expires_in,
18317
18318
  refreshToken: nextRefresh
18318
18319
  };
18319
18320
  }
18320
18321
  // ── token exchange ─────────────────────────────────────────────────────────
18322
+ // A refresh response repeats none of the connect-time data, and the platform keeps the connection's
18323
+ // `userData` to itself, so the only copy is inside the current token: read it back, to store it again in
18324
+ // the next one. A token the deserializer cannot read — a bare one saved before the service wrapped its
18325
+ // tokens — has nothing to carry over, and must not fail the refresh for that.
18326
+ #storedUserData(ctx) {
18327
+ try {
18328
+ return ctx.oauth.userData;
18329
+ } catch {
18330
+ return void 0;
18331
+ }
18332
+ }
18321
18333
  #serialize(accessToken, refreshToken, userData) {
18322
18334
  return this.props.serializeToken ? this.props.serializeToken({ accessToken, refreshToken, userData }) : accessToken;
18323
18335
  }
@@ -18342,6 +18354,9 @@ var OAuth2 = class {
18342
18354
  return Flowrunner.Request.post(this.props.tokenUrl).set(headers).send(params.toString());
18343
18355
  }
18344
18356
  };
18357
+ function userDataOf(token) {
18358
+ return token && typeof token === "object" ? token.userData : void 0;
18359
+ }
18345
18360
 
18346
18361
  // ../../flow-extension-runner/src/v2/polling-triggers/method-names.ts
18347
18362
  var POLLING_SYSTEM_METHOD = "handleTriggerPollingForEvent";
@@ -18654,11 +18669,14 @@ var RealtimeSelectInvocationSchema = z2.looseObject({
18654
18669
 
18655
18670
  // ../../flow-extension-runner/src/v2/realtime-triggers/verify.ts
18656
18671
  function verifyDeclarative(verify, rawBody, headers, config, webhookData) {
18672
+ const secret = verify.secret(config, { webhookData });
18673
+ if (!secret) {
18674
+ return true;
18675
+ }
18657
18676
  const provided = headers[verify.header] ?? headers[verify.header.toLowerCase()];
18658
18677
  if (!provided) {
18659
18678
  return false;
18660
18679
  }
18661
- const secret = verify.secret(config, { webhookData });
18662
18680
  const computed = Flowrunner.crypto.hmac(verify.algo, secret, rawBody ?? "", verify.encoding);
18663
18681
  if (!Flowrunner.crypto.timingSafeEqual(provided, computed)) {
18664
18682
  return false;
@@ -18735,12 +18753,32 @@ var RealtimeSetup = class {
18735
18753
  webhookData: invocation.webhookData ?? null,
18736
18754
  connectionId: invocation.connectionId
18737
18755
  }));
18756
+ this.#warnOnSuspectScope(result?.eventScopeId, ctx);
18738
18757
  return {
18739
18758
  webhookData: result?.webhookData,
18740
18759
  eventScopeId: result?.eventScopeId,
18741
18760
  refreshIntervalInSeconds: result?.refreshIntervalInSeconds
18742
18761
  };
18743
18762
  }
18763
+ // On ALL_APPS the platform routes every delivery of the shared callback by `eventScopeId`, so it has to name
18764
+ // the customer's tenant. A missing one leaves the app unroutable; the extension's own id or name is the
18765
+ // constant an author most often reaches for, and it puts every customer on one routing key. Neither is
18766
+ // refused — a warning, because a value equal to the name could in principle be a real tenant id.
18767
+ #warnOnSuspectScope(eventScopeId, ctx) {
18768
+ if (this.props.scope !== "ALL_APPS") {
18769
+ return;
18770
+ }
18771
+ const { id, name } = this.extension.props;
18772
+ if (eventScopeId == null || eventScopeId === "") {
18773
+ ctx.logger.warn(
18774
+ `[flow-extension:${id}] ALL_APPS subscribe returned no eventScopeId \u2014 deliveries on the shared callback cannot be routed to this app`
18775
+ );
18776
+ } else if (eventScopeId === id || eventScopeId === name) {
18777
+ ctx.logger.warn(
18778
+ `[flow-extension:${id}] ALL_APPS subscribe returned the extension's own ${eventScopeId === id ? "id" : "name"} ("${eventScopeId}") as eventScopeId \u2014 a constant puts every customer on one routing key; return the tenant id the provider's deliveries carry`
18779
+ );
18780
+ }
18781
+ }
18744
18782
  async #unsubscribe(invocation, ctx) {
18745
18783
  const result = await this.props.unsubscribe(ctx.bagWith({
18746
18784
  callbackUrl: invocation.callbackUrl,
@@ -18801,8 +18839,9 @@ var RealtimeSetup = class {
18801
18839
  const headers = invocation.headers ?? {};
18802
18840
  const body = invocation.body;
18803
18841
  const rawBody = invocation.rawBody;
18842
+ const query = invocation.queryParams ?? {};
18804
18843
  const webhookData = invocation.webhookData ?? null;
18805
- const handshake = await this.#handshake(body, headers, rawBody, webhookData, ctx);
18844
+ const handshake = await this.#handshake(body, headers, query, rawBody, webhookData, ctx);
18806
18845
  if (handshake) {
18807
18846
  return handshake;
18808
18847
  }
@@ -18814,7 +18853,7 @@ var RealtimeSetup = class {
18814
18853
  const result = await this.props.resolveEvents(ctx.bagWith({
18815
18854
  rawBody,
18816
18855
  headers,
18817
- query: invocation.queryParams ?? {},
18856
+ query,
18818
18857
  body,
18819
18858
  webhookData,
18820
18859
  connectionId: invocation.connectionId
@@ -18863,13 +18902,13 @@ var RealtimeSetup = class {
18863
18902
  * pod as a failed invocation and the provider receives a 500 telling it nothing. The hook runs BEFORE
18864
18903
  * verification, so the message reaches an unverified caller — throw what the provider may read.
18865
18904
  */
18866
- async #handshake(body, headers, rawBody, webhookData, ctx) {
18905
+ async #handshake(body, headers, query, rawBody, webhookData, ctx) {
18867
18906
  if (!this.props.handshake) {
18868
18907
  return isEmptyBody(body) ? { handshake: true, events: [] } : null;
18869
18908
  }
18870
18909
  let result;
18871
18910
  try {
18872
- result = await this.props.handshake(ctx.bagWith({ requestBody: body, headers, rawBody, webhookData }));
18911
+ result = await this.props.handshake(ctx.bagWith({ requestBody: body, headers, query, rawBody, webhookData }));
18873
18912
  } catch (error) {
18874
18913
  const message = error?.message ?? String(error);
18875
18914
  ctx.logger.error(`[flow-extension:${this.extension.id}] handshake failed \u2014 ${message}`);