@drawbridge/drawbridge-utils 0.0.114 → 0.0.116

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.
@@ -62,6 +62,7 @@ __export(connections_exports, {
62
62
  scopesMessage: () => scopesMessage,
63
63
  stepLabels: () => stepLabels,
64
64
  stepQueues: () => stepQueues,
65
+ stepRoutes: () => stepRoutes,
65
66
  tokenSettings: () => tokenSettings
66
67
  });
67
68
  module.exports = __toCommonJS(connections_exports);
@@ -446,6 +447,194 @@ var accessToken = async ({
446
447
  return next.accessToken;
447
448
  };
448
449
 
450
+ // lib/connections/icons/attentive.js
451
+ var attentive_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
452
+ <rect width="500" height="500" fill="#FFD967"/>
453
+ <path d="M239.369 127.404C260.863 122.013 284.964 132.569 295.576 152.039C321.796 201.286 347.928 250.567 374.131 299.825C380.149 311.989 381.244 326.564 376.733 339.41C371.446 355.097 358.039 367.69 342.107 372.089C326.274 376.67 308.351 372.871 295.741 362.255C288.865 356.892 284.161 349.359 280.354 341.629C261.869 306.95 243.478 272.217 225.071 237.501C214.409 218.614 187.221 212.656 169.622 225.315C168.104 227.309 164.159 226.857 164.72 223.796C176.911 202.569 189.361 181.497 201.662 160.331C205.183 154.428 208.214 148.129 212.967 143.091C219.844 135.272 229.263 129.782 239.374 127.404" fill="#1E1C1C"/>
454
+ <path d="M166.04 261.805C180.228 259.107 195.528 261.893 207.581 269.971C218.512 277.079 226.908 288.136 230.604 300.657C234.835 314.103 233.614 329.124 227.485 341.788C220.097 356.875 205.782 368.543 189.317 372.089C173.957 375.652 157.089 372.386 144.304 363.103C132.971 355.295 124.912 342.989 121.891 329.581C118.943 316.636 120.725 302.656 127.002 290.938C134.699 275.951 149.503 264.933 166.046 261.811" fill="#1E1C1C"/>
455
+ </svg>`;
456
+
457
+ // lib/connections/attentive.js
458
+ var attentive_default2 = {
459
+ auth: {
460
+ oauth: {
461
+ // NAMES of the env vars holding OUR app's client — set at registration,
462
+ // never before. No `headers` on the client: Attentive takes credentials
463
+ // as form fields, which is the runner's default.
464
+ client: {
465
+ id: "ATTENTIVE_OAUTH_CLIENT_ID",
466
+ secret: "ATTENTIVE_OAUTH_CLIENT_SECRET"
467
+ },
468
+ urls: {
469
+ authorize: "https://ui.attentivemobile.com/integrations/oauth-install",
470
+ redirect: "/api/connection/attentive/callback",
471
+ token: "https://api.attentivemobile.com/v1/authorization-codes/tokens"
472
+ }
473
+ },
474
+ type: "oauth"
475
+ },
476
+ // EVERYTHING A MERCHANT READS. `errors` would live in here too — the
477
+ // connection DOCUMENT carries its own `errors` array and is spread OVER the
478
+ // resolved manifest downstream, so a top-level one would never render.
479
+ content: {
480
+ // SAYS WHAT ACTUALLY HAPPENS. This used to promise that disconnecting
481
+ // revokes Drawbridge's access, and it cannot: Attentive documents no
482
+ // revocation endpoint, and their authentication page states an access
483
+ // token "does not expire". So the grant survives a disconnect forever
484
+ // unless the merchant removes the integration at Attentive, and the copy
485
+ // has to say so rather than let them believe otherwise.
486
+ confirm: "Disconnecting removes Drawbridge's stored Attentive token. Attentive does not offer a way for us to revoke it, so remove the Drawbridge integration in Attentive as well if you want its access fully withdrawn. Your subscribers stay in both Attentive and Drawbridge \u2014 neither list is deleted.",
487
+ description: [
488
+ "Attentive is where your SMS marketing lives, and this connection is becoming the way your Drawbridge contacts sync into an Attentive segment.",
489
+ "You authorize Drawbridge from inside Attentive and can revoke that access there at any time. Drawbridge never sees or stores your Attentive password.",
490
+ "Subscriber syncing is not live yet, so connecting today does nothing except choose the segment it will use when it ships."
491
+ ],
492
+ excerpt: "Sync your Drawbridge contacts into an Attentive segment.",
493
+ guide: [
494
+ "Press Connect. Drawbridge sends you to Attentive to approve access.",
495
+ "Sign in to Attentive if you are not already, and authorize the permissions listed.",
496
+ "You are returned here \u2014 choose which Attentive segment your contacts should sync into."
497
+ ]
498
+ },
499
+ // A contact destination, like Klaviyo and Mailchimp — a merchant could
500
+ // reasonably keep several up to date at once.
501
+ exclusive: false,
502
+ feature: "organization:connection:attentive",
503
+ fields: [
504
+ {
505
+ input: "select",
506
+ key: "segment",
507
+ label: "Attentive segment",
508
+ message: "Contacts your campaigns collect are synced into this segment.",
509
+ hook: "resources.audiences",
510
+ required: true
511
+ // No `search : false` here, and that is a first: /v2/segments takes a
512
+ // `name` filter (partial match, cited above), so this picker searches
513
+ // the ACCOUNT — Klaviyo and Mailchimp can only match the fetched page.
514
+ }
515
+ ],
516
+ group: "contacts",
517
+ // A HOOK'S VALUE IS ITS ANSWER. The consent is stored and can be revoked;
518
+ // nothing else is built yet, because subscriber sync has not shipped. Every
519
+ // false here is "not yet" rather than "never" — when the sync lands, probe
520
+ // and contacts.sync are the first to flip.
521
+ hooks: {
522
+ auth: {
523
+ // The exchange already yields the tokens, and Attentive documents no
524
+ // account-identity endpoint to enrich them with — Klaviyo's connect
525
+ // reads the account name back; this has nothing cited to read. The
526
+ // callback stores the tokens and skips enrichment on `unimplemented`.
527
+ // FALSE, NOT {}. `{}` means "supported, implemented in the repo with the
528
+ // dependencies", and nothing anywhere implements either of these —
529
+ // there is nothing for them to do. The exchange already yields the
530
+ // tokens and Attentive documents no account-identity endpoint to
531
+ // enrich them with, so connect has nothing to add; and they document
532
+ // no revocation endpoint at all, so disconnect has nothing to call.
533
+ // Recorded as a decision rather than left as an unkept promise.
534
+ connect: false,
535
+ disconnect: false,
536
+ probe: false,
537
+ scopes: false,
538
+ // THE ONE THING WRAPPED, and it is about the response rather than the
539
+ // request. Attentive's token reply carries expires_in : 900 while their
540
+ // auth overview says access tokens "do not expire" — and no refresh
541
+ // token exists to renew with. Storing that expiry would have
542
+ // accessToken() declaring the credential spent fifteen minutes after
543
+ // consent, with nothing to renew it: every connection would demand
544
+ // reconnecting four times an hour.
545
+ //
546
+ // The overview's answer is modelled — the expiry is dropped, so the
547
+ // token is treated as long-lived. Registration item 1 in the header is
548
+ // the live exchange that proves this right or wrong.
549
+ token: async (args) => {
550
+ const minted = await authToken(args);
551
+ return { ...minted, expiresIn: null };
552
+ }
553
+ },
554
+ commerce: false,
555
+ contacts: { remove: false, sync: false },
556
+ email: false,
557
+ inbound: false,
558
+ lifecycle: false,
559
+ resources: {
560
+ // The segments a merchant can sync into, for the picker on their
561
+ // connection.
562
+ //
563
+ // GET /v2/segments (cited in the header). `limit` caps at 1000 in their
564
+ // own spec, defaulting to 20 — low enough that leaving it unset would
565
+ // show a picker quietly missing most of a real account. The response's
566
+ // only identifier is `externalId`, so an entry without one cannot be
567
+ // stored and is dropped.
568
+ audiences: async ({ cursor, fetcher = fetch, limit = 100, search, token }) => {
569
+ const query = new URLSearchParams({
570
+ limit: String(Math.min(limit, 1e3)),
571
+ ...cursor && { cursor },
572
+ ...(search == null ? void 0 : search.value) && { name: String(search.value).trim() }
573
+ });
574
+ const response = await fetcher(
575
+ "https://api.attentivemobile.com/v2/segments?" + query,
576
+ {
577
+ headers: { authorization: "Bearer " + token },
578
+ signal: AbortSignal.timeout(15e3)
579
+ }
580
+ );
581
+ if (!response.ok) {
582
+ throw Object.assign(
583
+ new Error("Attentive refused the request (" + response.status + ")"),
584
+ { status: response.status }
585
+ );
586
+ }
587
+ const body = await response.json();
588
+ return {
589
+ items: ((body == null ? void 0 : body.segments) || []).filter((segment) => segment == null ? void 0 : segment.externalId).map((segment) => ({ id: segment.externalId, title: (segment == null ? void 0 : segment.name) || segment.externalId })),
590
+ pageInfo: {
591
+ endCursor: (body == null ? void 0 : body.hasMore) ? (body == null ? void 0 : body.cursor) || null : null,
592
+ hasNextPage: Boolean(body == null ? void 0 : body.hasMore)
593
+ }
594
+ };
595
+ },
596
+ prices: false,
597
+ products: false,
598
+ promotions: false
599
+ },
600
+ segment: false,
601
+ sms: false,
602
+ webhook: false
603
+ },
604
+ icon: attentive_default,
605
+ requires: [
606
+ "ATTENTIVE_OAUTH_CLIENT_ID",
607
+ "ATTENTIVE_OAUTH_CLIENT_SECRET"
608
+ ],
609
+ slug: "attentive",
610
+ // A consent with no segment chosen is authenticated and inert — the sync,
611
+ // when it ships, needs somewhere to put people.
612
+ status: (data2) => {
613
+ var _a;
614
+ return ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.segment) ? data2.status : "pending";
615
+ },
616
+ // No steps: subscriber sync has not shipped, so this vendor contributes
617
+ // nothing to a workflow yet. An empty steps object is the honest declaration.
618
+ steps: {},
619
+ tasks: (data2) => {
620
+ var _a;
621
+ return [
622
+ ...((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.segment) ? [] : [
623
+ {
624
+ message: "Choose which Attentive segment your contacts should sync into. Until you do, nothing is being synced.",
625
+ title: "Choose a segment"
626
+ }
627
+ ],
628
+ {
629
+ message: "Contact syncing to Attentive segments has not shipped yet. Nothing is being sent to Attentive right now.",
630
+ title: "Subscriber sync not available yet",
631
+ type: "warning"
632
+ }
633
+ ];
634
+ },
635
+ title: "Attentive"
636
+ };
637
+
449
638
  // lib/connections/icons/drawbridge.js
450
639
  var drawbridge_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
451
640
  <rect width="500" height="500" fill="#BAEC5F"/>
@@ -528,6 +717,21 @@ var field = {
528
717
  }
529
718
  };
530
719
  var connection = {
720
+ attentive: {
721
+ key: "organization:connection:attentive",
722
+ error: "Plan does not include Attentive connection",
723
+ feature: "Attentive connection"
724
+ },
725
+ // Klaviyo shipped without an entry here, which meant no plan GRANTED its
726
+ // key and the feature gate denied every non-admin request — a latent 403
727
+ // found while adding Attentive. getPlanFeature answers granted:false for a
728
+ // key absent from the plan's map, so a manifest feature key that appears in
729
+ // no plan list is a connection only admins can manage.
730
+ klaviyo: {
731
+ key: "organization:connection:klaviyo",
732
+ error: "Plan does not include Klaviyo connection",
733
+ feature: "Klaviyo connection"
734
+ },
531
735
  mailchimp: {
532
736
  key: "organization:connection:mailchimp",
533
737
  error: "Plan does not include Mailchimp connection",
@@ -705,6 +909,8 @@ var overage = (actionCents) => ({
705
909
  });
706
910
  var all = {
707
911
  features: (array = []) => featuresFor([
912
+ connection.attentive.key,
913
+ connection.klaviyo.key,
708
914
  connection.mailchimp.key,
709
915
  connection.sendgrid.key,
710
916
  connection.shopify.key,
@@ -1996,10 +2202,14 @@ var mailchimp_default2 = {
1996
2202
  // contacts.sync are the first to flip.
1997
2203
  hooks: {
1998
2204
  auth: {
1999
- // Implemented outside this package: storing a typed key needs no vendor
2000
- // call, so the api's own form handler does it.
2001
- connect: {},
2002
- disconnect: {},
2205
+ // FALSE, NOT {}. `{}` promises an implementation living in the repo that
2206
+ // holds the dependencies, and there is no implementation anywhere
2207
+ // because there is nothing to implement: storing and clearing a typed
2208
+ // key needs no vendor call, and the api's own form handler does it.
2209
+ // Declaring `{}` made the coverage check chase a body that does not
2210
+ // exist, and made a caller wait on an answer that never comes.
2211
+ connect: false,
2212
+ disconnect: false,
2003
2213
  probe: false,
2004
2214
  scopes: false,
2005
2215
  // Keys today. When Mailchimp's OAuth lands this becomes a wrapper that
@@ -2220,10 +2430,29 @@ var shopify_default2 = {
2220
2430
  // re-registers rather than answering "is this token still good", and
2221
2431
  // scope drift is its own hook because a token can be perfectly valid
2222
2432
  // while the grant is too narrow.
2223
- connect: {},
2224
- disconnect: {},
2433
+ //
2434
+ // connect and disconnect are FALSE rather than `{}`: there is nothing to
2435
+ // call on either side. The install already hands the callback everything
2436
+ // it stores, and a Shopify grant is withdrawn by UNINSTALLING the app in
2437
+ // Shopify admin — which Drawbridge learns about from the app_uninstalled
2438
+ // webhook rather than by asking. `{}` claimed a body implemented
2439
+ // elsewhere; none exists, and none could.
2440
+ connect: false,
2441
+ disconnect: false,
2225
2442
  probe: false,
2226
- scopes: {},
2443
+ // WHETHER THE GRANT IS STILL WIDE ENOUGH. A token can be perfectly valid
2444
+ // and still too narrow — a deploy that adds a scope leaves every existing
2445
+ // install short of it, and no webhook fires to say so.
2446
+ //
2447
+ // The comparison is the vendor's, so it belongs here. Reading WHICH
2448
+ // scopes a store granted is not: that lives in the `shop` collection and
2449
+ // needs a controller, which is precisely what a hook in a published
2450
+ // package must not be handed. The caller reads the grant and passes the
2451
+ // string; this answers what is missing from it.
2452
+ //
2453
+ // `shopify` is injected for the same reason it is everywhere else — this
2454
+ // package cannot import @drawbridge/shopify, which depends on it.
2455
+ scopes: ({ scope, shopify }) => scope ? shopify.oauth.missingScopes(scope) : null,
2227
2456
  // Shopify's install grant is exchanged inside its own app flow, not
2228
2457
  // through the shared OAuth runner.
2229
2458
  token: false
@@ -2277,8 +2506,65 @@ var shopify_default2 = {
2277
2506
  // variant and arrives with it, so there is nothing for prices to answer
2278
2507
  // that products does not already.
2279
2508
  prices: false,
2280
- products: {},
2281
- promotions: {}
2509
+ // WHAT THE VENDOR ANSWERS, shaped for a picker. Both of these were api
2510
+ // ROUTES — /organization/:organization/shopify/products and
2511
+ // .../connection/:id/shopify/discounts — vendor-named urls in a service
2512
+ // that is supposed to have none, reachable only by knowing the path.
2513
+ // They are the same two questions every other vendor answers through
2514
+ // resources.*, so they answer them the same way now.
2515
+ //
2516
+ // `shopify` is INJECTED: this package cannot import @drawbridge/shopify,
2517
+ // which depends on it. What arrives is the SDK's pure HTTP namespaces
2518
+ // and nothing else — no controller, no collection access. Resolving the
2519
+ // credential is the caller's job because it is Drawbridge's job: the
2520
+ // admin token refreshes and writes itself back, which is service work,
2521
+ // not vendor work.
2522
+ products: async ({ cursor, limit = 100, search, settings, shopify, sort }) => {
2523
+ var _a, _b, _c, _d;
2524
+ const products = await shopify.storefront.getProducts({
2525
+ cursor,
2526
+ domain: settings == null ? void 0 : settings.domain,
2527
+ limit: Number(limit),
2528
+ search: (search == null ? void 0 : search.value) || null,
2529
+ sort,
2530
+ storefrontAccessToken: settings == null ? void 0 : settings.storefrontAccessToken
2531
+ });
2532
+ return {
2533
+ items: ((products == null ? void 0 : products.edges) || []).map((edge) => edge.node),
2534
+ pageInfo: {
2535
+ endCursor: ((_a = products == null ? void 0 : products.pageInfo) == null ? void 0 : _a.endCursor) || null,
2536
+ hasNextPage: Boolean((_b = products == null ? void 0 : products.pageInfo) == null ? void 0 : _b.hasNextPage),
2537
+ hasPreviousPage: Boolean((_c = products == null ? void 0 : products.pageInfo) == null ? void 0 : _c.hasPreviousPage),
2538
+ startCursor: ((_d = products == null ? void 0 : products.pageInfo) == null ? void 0 : _d.startCursor) || null
2539
+ }
2540
+ };
2541
+ },
2542
+ promotions: async ({ cursor, limit = 100, search, settings, shopify }) => {
2543
+ var _a, _b;
2544
+ const discounts = await shopify.admin.getDiscounts({
2545
+ adminAccessToken: settings == null ? void 0 : settings.adminAccessToken,
2546
+ cursor,
2547
+ domain: settings == null ? void 0 : settings.domain,
2548
+ limit: Number(limit),
2549
+ search: (search == null ? void 0 : search.value) || null
2550
+ });
2551
+ return {
2552
+ // The GLOBAL id is what Shopify returns and the bare id is what a
2553
+ // picker stores, which is why the tail is taken here rather than by
2554
+ // each caller that happened to remember.
2555
+ items: ((discounts == null ? void 0 : discounts.edges) || []).map((edge) => {
2556
+ var _a2, _b2, _c;
2557
+ return {
2558
+ id: String(((_a2 = edge == null ? void 0 : edge.node) == null ? void 0 : _a2.id) || "").split("/").pop(),
2559
+ title: (_c = (_b2 = edge == null ? void 0 : edge.node) == null ? void 0 : _b2.codeDiscount) == null ? void 0 : _c.title
2560
+ };
2561
+ }),
2562
+ pageInfo: {
2563
+ endCursor: ((_a = discounts == null ? void 0 : discounts.pageInfo) == null ? void 0 : _a.endCursor) || null,
2564
+ hasNextPage: Boolean((_b = discounts == null ? void 0 : discounts.pageInfo) == null ? void 0 : _b.hasNextPage)
2565
+ }
2566
+ };
2567
+ }
2282
2568
  },
2283
2569
  // Drawbridge posts to a merchant's own endpoint, never through a vendor.
2284
2570
  webhook: false
@@ -2629,10 +2915,12 @@ var webhook_default = {
2629
2915
  // connect generates a secret rather than proving a credential.
2630
2916
  hooks: {
2631
2917
  auth: {
2632
- // Minting and clearing a secret needs no vendor call, so the api's own
2633
- // handler does both.
2634
- connect: {},
2635
- disconnect: {},
2918
+ // FALSE, NOT {}. There is no vendor here at all connecting mints a
2919
+ // secret and disconnecting clears it, both done by the api's own
2920
+ // handler. `{}` would promise a body implemented elsewhere, and none
2921
+ // exists or could.
2922
+ connect: false,
2923
+ disconnect: false,
2636
2924
  probe: false,
2637
2925
  scopes: false,
2638
2926
  // Nothing to mint. Connecting generates a secret; there is no vendor.
@@ -2875,6 +3163,7 @@ var stepLabels = (catalog = connections) => Object.fromEntries(
2875
3163
  )
2876
3164
  );
2877
3165
  var connections = Object.freeze({
3166
+ attentive: build(attentive_default2),
2878
3167
  drawbridge: build(drawbridge_default2),
2879
3168
  hubspot: build(hubspot_default),
2880
3169
  klaviyo: build(klaviyo_default2),
@@ -2956,6 +3245,15 @@ var runHook = async (slug, name, args = {}) => {
2956
3245
  var stepQueues = (env = {}) => Object.fromEntries(
2957
3246
  connectionSteps(env).map((step) => [step.type, step.queue])
2958
3247
  );
3248
+ var stepRoutes = (env = {}) => {
3249
+ const live = stepQueues(env);
3250
+ return Object.freeze({
3251
+ ...live,
3252
+ ...Object.fromEntries(
3253
+ Object.entries(RETIRED).filter(([, replacement]) => live[replacement]).map(([retired, replacement]) => [retired, live[replacement]])
3254
+ )
3255
+ });
3256
+ };
2959
3257
  var scopesMessage = "Shopify permissions are out of date. Open the Drawbridge app in your Shopify admin to approve the updated permissions.";
2960
3258
  var mergeSettings = ({ existing, incoming }) => {
2961
3259
  if (!existing || typeof existing !== "object") return incoming;
@@ -3064,5 +3362,6 @@ var resolveConnection = (item, data2, env = {}) => {
3064
3362
  scopesMessage,
3065
3363
  stepLabels,
3066
3364
  stepQueues,
3365
+ stepRoutes,
3067
3366
  tokenSettings
3068
3367
  });