@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.
@@ -519,6 +519,262 @@ const accessToken = async ({
519
519
 
520
520
  };
521
521
 
522
+ // Attentive, exported from the brand kit and left as authored — the yellow
523
+ // field and the mark's fills are the vendor's own, not a recolour.
524
+ //
525
+ // A .js wrapper around otherwise untouched SVG so `node --test` can run against
526
+ // lib/ directly. A bare .svg import would need a bundler loader and force the
527
+ // tests through dist.
528
+ var icon$4 = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
529
+ <rect width="500" height="500" fill="#FFD967"/>
530
+ <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"/>
531
+ <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"/>
532
+ </svg>`;
533
+
534
+ // Attentive — SMS-first marketing, installed as a distributed Attentive app.
535
+ //
536
+ // EVERY VENDOR FACT BELOW IS CITED from docs.attentive.com (fetched 2026-09-01):
537
+ //
538
+ // authorize docs.attentive.com/docs/authentication — the install prompt is
539
+ // ui.attentivemobile.com/integrations/oauth-install, documented
540
+ // with `client_id` and `redirect_uri` parameters.
541
+ //
542
+ // token docs.attentive.com/reference/createtokenviaauthorizationcode.md —
543
+ // POST api.attentivemobile.com/v1/authorization-codes/tokens, all
544
+ // parameters as FORM FIELDS (grant_type, code, redirect_uri,
545
+ // client_id, client_secret). Credentials in the body is our
546
+ // runner's default, so unlike Klaviyo there is nothing to wrap
547
+ // for auth — see hooks.auth.token for what IS wrapped, and why.
548
+ //
549
+ // response { access_token, id_token, token_type : "Bearer",
550
+ // expires_in : 900 } — and NO refresh_token, which matters below.
551
+ //
552
+ // scopes events:write, ecommerce:write, subscriptions:write,
553
+ // attributes:write, privacy_requests:write; the segments API
554
+ // takes segments:read or segments:write. Scopes ride on the app's
555
+ // registration (the generated distribution URL carries them), not
556
+ // on each consent — so none are declared here.
557
+ //
558
+ // segments docs.attentive.com/reference/listsegments.md —
559
+ // GET api.attentivemobile.com/v2/segments with `name` (partial
560
+ // match), `cursor` and `limit` (1-1000, default 20); responds
561
+ // { segments : [ { externalId, name, ... } ], cursor, hasMore }.
562
+ //
563
+ // DORMANT UNTIL REGISTERED. `requires` names the client credentials that only
564
+ // exist once the Attentive app is created (their console: enable distribution,
565
+ // set the redirect URL, Generate Credentials). Until those env vars land, no
566
+ // deployment offers this connection — the manifest ships complete and inert.
567
+ //
568
+ // THREE THINGS TO VERIFY AT REGISTRATION, because the docs conflict or are
569
+ // silent, and only a live install answers them:
570
+ //
571
+ // 1. TOKEN LIFETIME. The auth overview says access tokens "do not expire";
572
+ // the token response carries expires_in : 900 and no refresh_token. If
573
+ // the token really died at 15 minutes with nothing to renew it, every
574
+ // connection would need reconnecting a quarter-hour after consent.
575
+ // hooks.auth.token below models the overview's answer — see its comment.
576
+ //
577
+ // 2. STATE ECHO. Our callback requires the parked `state` to round-trip, and
578
+ // their authorize URL is documented with only client_id and redirect_uri.
579
+ // If the consent drops unknown params, the flow breaks at the callback.
580
+ //
581
+ // 3. PER-ENVIRONMENT REDIRECTS. The redirect must byte-match the app's
582
+ // registration, and dev and prod have different callback hosts — one app
583
+ // with multiple redirect URLs, or two apps like Shopify's two tomls.
584
+ var attentive = {
585
+ auth : {
586
+ oauth : {
587
+ // NAMES of the env vars holding OUR app's client — set at registration,
588
+ // never before. No `headers` on the client: Attentive takes credentials
589
+ // as form fields, which is the runner's default.
590
+ client : {
591
+ id : 'ATTENTIVE_OAUTH_CLIENT_ID',
592
+ secret : 'ATTENTIVE_OAUTH_CLIENT_SECRET'
593
+ },
594
+ urls : {
595
+ authorize : 'https://ui.attentivemobile.com/integrations/oauth-install',
596
+ redirect : '/api/connection/attentive/callback',
597
+ token : 'https://api.attentivemobile.com/v1/authorization-codes/tokens'
598
+ }
599
+ },
600
+ type : 'oauth'
601
+ },
602
+ // EVERYTHING A MERCHANT READS. `errors` would live in here too — the
603
+ // connection DOCUMENT carries its own `errors` array and is spread OVER the
604
+ // resolved manifest downstream, so a top-level one would never render.
605
+ content : {
606
+ // SAYS WHAT ACTUALLY HAPPENS. This used to promise that disconnecting
607
+ // revokes Drawbridge's access, and it cannot: Attentive documents no
608
+ // revocation endpoint, and their authentication page states an access
609
+ // token "does not expire". So the grant survives a disconnect forever
610
+ // unless the merchant removes the integration at Attentive, and the copy
611
+ // has to say so rather than let them believe otherwise.
612
+ 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 — neither list is deleted.',
613
+ description : [
614
+ 'Attentive is where your SMS marketing lives, and this connection is becoming the way your Drawbridge contacts sync into an Attentive segment.',
615
+ 'You authorize Drawbridge from inside Attentive and can revoke that access there at any time. Drawbridge never sees or stores your Attentive password.',
616
+ 'Subscriber syncing is not live yet, so connecting today does nothing except choose the segment it will use when it ships.'
617
+ ],
618
+ excerpt : 'Sync your Drawbridge contacts into an Attentive segment.',
619
+ guide : [
620
+ 'Press Connect. Drawbridge sends you to Attentive to approve access.',
621
+ 'Sign in to Attentive if you are not already, and authorize the permissions listed.',
622
+ 'You are returned here — choose which Attentive segment your contacts should sync into.'
623
+ ]
624
+ },
625
+ // A contact destination, like Klaviyo and Mailchimp — a merchant could
626
+ // reasonably keep several up to date at once.
627
+ exclusive : false,
628
+ feature : 'organization:connection:attentive',
629
+ fields : [
630
+ {
631
+ input : 'select',
632
+ key : 'segment',
633
+ label : 'Attentive segment',
634
+ message : 'Contacts your campaigns collect are synced into this segment.',
635
+ hook : 'resources.audiences',
636
+ required : true
637
+ // No `search : false` here, and that is a first: /v2/segments takes a
638
+ // `name` filter (partial match, cited above), so this picker searches
639
+ // the ACCOUNT — Klaviyo and Mailchimp can only match the fetched page.
640
+ }
641
+ ],
642
+ group : 'contacts',
643
+ // A HOOK'S VALUE IS ITS ANSWER. The consent is stored and can be revoked;
644
+ // nothing else is built yet, because subscriber sync has not shipped. Every
645
+ // false here is "not yet" rather than "never" — when the sync lands, probe
646
+ // and contacts.sync are the first to flip.
647
+ hooks : {
648
+
649
+ auth : {
650
+ // The exchange already yields the tokens, and Attentive documents no
651
+ // account-identity endpoint to enrich them with — Klaviyo's connect
652
+ // reads the account name back; this has nothing cited to read. The
653
+ // callback stores the tokens and skips enrichment on `unimplemented`.
654
+ // FALSE, NOT {}. `{}` means "supported, implemented in the repo with the
655
+ // dependencies", and nothing anywhere implements either of these —
656
+ // there is nothing for them to do. The exchange already yields the
657
+ // tokens and Attentive documents no account-identity endpoint to
658
+ // enrich them with, so connect has nothing to add; and they document
659
+ // no revocation endpoint at all, so disconnect has nothing to call.
660
+ // Recorded as a decision rather than left as an unkept promise.
661
+ connect : false,
662
+ disconnect : false,
663
+ probe : false,
664
+ scopes : false,
665
+ // THE ONE THING WRAPPED, and it is about the response rather than the
666
+ // request. Attentive's token reply carries expires_in : 900 while their
667
+ // auth overview says access tokens "do not expire" — and no refresh
668
+ // token exists to renew with. Storing that expiry would have
669
+ // accessToken() declaring the credential spent fifteen minutes after
670
+ // consent, with nothing to renew it: every connection would demand
671
+ // reconnecting four times an hour.
672
+ //
673
+ // The overview's answer is modelled — the expiry is dropped, so the
674
+ // token is treated as long-lived. Registration item 1 in the header is
675
+ // the live exchange that proves this right or wrong.
676
+ token : async ( args ) => {
677
+
678
+ const minted = await authToken( args );
679
+
680
+ return { ...minted, expiresIn : null };
681
+
682
+ }
683
+ },
684
+ commerce : false,
685
+ contacts : { remove : false, sync : false },
686
+ email : false,
687
+ inbound : false,
688
+ lifecycle : false,
689
+ resources : {
690
+
691
+ // The segments a merchant can sync into, for the picker on their
692
+ // connection.
693
+ //
694
+ // GET /v2/segments (cited in the header). `limit` caps at 1000 in their
695
+ // own spec, defaulting to 20 — low enough that leaving it unset would
696
+ // show a picker quietly missing most of a real account. The response's
697
+ // only identifier is `externalId`, so an entry without one cannot be
698
+ // stored and is dropped.
699
+ audiences : async ({ cursor, fetcher = fetch, limit = 100, search, token }) => {
700
+
701
+ const query = new URLSearchParams({
702
+ limit : String( Math.min( limit, 1000 ) ),
703
+ ...( cursor && { cursor } ),
704
+ ...( search?.value && { name : String( search.value ).trim() } )
705
+ });
706
+
707
+ const response = await fetcher(
708
+ 'https://api.attentivemobile.com/v2/segments?' + query,
709
+ {
710
+ headers : { authorization : 'Bearer ' + token },
711
+ signal : AbortSignal.timeout( 15000 )
712
+ }
713
+ );
714
+
715
+ if( ! response.ok ){
716
+
717
+ throw Object.assign(
718
+ new Error( 'Attentive refused the request (' + response.status + ')' ),
719
+ { status : response.status }
720
+ );
721
+
722
+ }
723
+
724
+ const body = await response.json();
725
+
726
+ return {
727
+ items : ( body?.segments || [] )
728
+ .filter( ( segment ) => segment?.externalId )
729
+ .map( ( segment ) => ({ id : segment.externalId, title : segment?.name || segment.externalId }) ),
730
+ pageInfo : {
731
+ endCursor : body?.hasMore ? ( body?.cursor || null ) : null,
732
+ hasNextPage : Boolean( body?.hasMore )
733
+ }
734
+ };
735
+
736
+ },
737
+ prices : false,
738
+ products : false,
739
+ promotions : false
740
+
741
+ },
742
+ segment : false,
743
+ sms : false,
744
+ webhook : false
745
+
746
+ },
747
+ icon: icon$4,
748
+ requires : [
749
+ 'ATTENTIVE_OAUTH_CLIENT_ID',
750
+ 'ATTENTIVE_OAUTH_CLIENT_SECRET'
751
+ ],
752
+ slug : 'attentive',
753
+ // A consent with no segment chosen is authenticated and inert — the sync,
754
+ // when it ships, needs somewhere to put people.
755
+ status : ( data ) => ( data?.settings?.segment ? data.status : 'pending' ),
756
+ // No steps: subscriber sync has not shipped, so this vendor contributes
757
+ // nothing to a workflow yet. An empty steps object is the honest declaration.
758
+ steps : {},
759
+ tasks : ( data ) => [
760
+ ...( data?.settings?.segment
761
+ ? []
762
+ : [
763
+ {
764
+ message : 'Choose which Attentive segment your contacts should sync into. Until you do, nothing is being synced.',
765
+ title : 'Choose a segment'
766
+ }
767
+ ]
768
+ ),
769
+ {
770
+ message : 'Contact syncing to Attentive segments has not shipped yet. Nothing is being sent to Attentive right now.',
771
+ title : 'Subscriber sync not available yet',
772
+ type : 'warning'
773
+ }
774
+ ],
775
+ title : 'Attentive'
776
+ };
777
+
522
778
  // Drawbridge, exported from the brand kit and left as authored — the fills are the
523
779
  // vendor's own mark, not a recolour.
524
780
  //
@@ -1775,10 +2031,14 @@ var mailchimp = {
1775
2031
  hooks : {
1776
2032
 
1777
2033
  auth : {
1778
- // Implemented outside this package: storing a typed key needs no vendor
1779
- // call, so the api's own form handler does it.
1780
- connect : {},
1781
- disconnect : {},
2034
+ // FALSE, NOT {}. `{}` promises an implementation living in the repo that
2035
+ // holds the dependencies, and there is no implementation anywhere
2036
+ // because there is nothing to implement: storing and clearing a typed
2037
+ // key needs no vendor call, and the api's own form handler does it.
2038
+ // Declaring `{}` made the coverage check chase a body that does not
2039
+ // exist, and made a caller wait on an answer that never comes.
2040
+ connect : false,
2041
+ disconnect : false,
1782
2042
  probe : false,
1783
2043
  scopes : false,
1784
2044
  // Keys today. When Mailchimp's OAuth lands this becomes a wrapper that
@@ -2079,10 +2339,30 @@ var shopify = {
2079
2339
  // re-registers rather than answering "is this token still good", and
2080
2340
  // scope drift is its own hook because a token can be perfectly valid
2081
2341
  // while the grant is too narrow.
2082
- connect : {},
2083
- disconnect : {},
2342
+ //
2343
+ // connect and disconnect are FALSE rather than `{}`: there is nothing to
2344
+ // call on either side. The install already hands the callback everything
2345
+ // it stores, and a Shopify grant is withdrawn by UNINSTALLING the app in
2346
+ // Shopify admin — which Drawbridge learns about from the app_uninstalled
2347
+ // webhook rather than by asking. `{}` claimed a body implemented
2348
+ // elsewhere; none exists, and none could.
2349
+ connect : false,
2350
+ disconnect : false,
2084
2351
  probe : false,
2085
- scopes : {},
2352
+
2353
+ // WHETHER THE GRANT IS STILL WIDE ENOUGH. A token can be perfectly valid
2354
+ // and still too narrow — a deploy that adds a scope leaves every existing
2355
+ // install short of it, and no webhook fires to say so.
2356
+ //
2357
+ // The comparison is the vendor's, so it belongs here. Reading WHICH
2358
+ // scopes a store granted is not: that lives in the `shop` collection and
2359
+ // needs a controller, which is precisely what a hook in a published
2360
+ // package must not be handed. The caller reads the grant and passes the
2361
+ // string; this answers what is missing from it.
2362
+ //
2363
+ // `shopify` is injected for the same reason it is everywhere else — this
2364
+ // package cannot import @drawbridge/shopify, which depends on it.
2365
+ scopes : ({ scope, shopify }) => ( scope ? shopify.oauth.missingScopes( scope ) : null ),
2086
2366
  // Shopify's install grant is exchanged inside its own app flow, not
2087
2367
  // through the shared OAuth runner.
2088
2368
  token : false
@@ -2144,8 +2424,68 @@ var shopify = {
2144
2424
  // variant and arrives with it, so there is nothing for prices to answer
2145
2425
  // that products does not already.
2146
2426
  prices : false,
2147
- products : {},
2148
- promotions : {}
2427
+
2428
+ // WHAT THE VENDOR ANSWERS, shaped for a picker. Both of these were api
2429
+ // ROUTES — /organization/:organization/shopify/products and
2430
+ // .../connection/:id/shopify/discounts — vendor-named urls in a service
2431
+ // that is supposed to have none, reachable only by knowing the path.
2432
+ // They are the same two questions every other vendor answers through
2433
+ // resources.*, so they answer them the same way now.
2434
+ //
2435
+ // `shopify` is INJECTED: this package cannot import @drawbridge/shopify,
2436
+ // which depends on it. What arrives is the SDK's pure HTTP namespaces
2437
+ // and nothing else — no controller, no collection access. Resolving the
2438
+ // credential is the caller's job because it is Drawbridge's job: the
2439
+ // admin token refreshes and writes itself back, which is service work,
2440
+ // not vendor work.
2441
+ products : async ({ cursor, limit = 100, search, settings, shopify, sort }) => {
2442
+
2443
+ const products = await shopify.storefront.getProducts({
2444
+ cursor,
2445
+ domain : settings?.domain,
2446
+ limit : Number( limit ),
2447
+ search : search?.value || null,
2448
+ sort,
2449
+ storefrontAccessToken : settings?.storefrontAccessToken
2450
+ });
2451
+
2452
+ return {
2453
+ items : ( products?.edges || [] ).map( ( edge ) => edge.node ),
2454
+ pageInfo : {
2455
+ endCursor : products?.pageInfo?.endCursor || null,
2456
+ hasNextPage : Boolean( products?.pageInfo?.hasNextPage ),
2457
+ hasPreviousPage : Boolean( products?.pageInfo?.hasPreviousPage ),
2458
+ startCursor : products?.pageInfo?.startCursor || null
2459
+ }
2460
+ };
2461
+
2462
+ },
2463
+
2464
+ promotions : async ({ cursor, limit = 100, search, settings, shopify }) => {
2465
+
2466
+ const discounts = await shopify.admin.getDiscounts({
2467
+ adminAccessToken : settings?.adminAccessToken,
2468
+ cursor,
2469
+ domain : settings?.domain,
2470
+ limit : Number( limit ),
2471
+ search : search?.value || null
2472
+ });
2473
+
2474
+ return {
2475
+ // The GLOBAL id is what Shopify returns and the bare id is what a
2476
+ // picker stores, which is why the tail is taken here rather than by
2477
+ // each caller that happened to remember.
2478
+ items : ( discounts?.edges || [] ).map( ( edge ) => ({
2479
+ id : String( edge?.node?.id || '' ).split( '/' ).pop(),
2480
+ title : edge?.node?.codeDiscount?.title
2481
+ }) ),
2482
+ pageInfo : {
2483
+ endCursor : discounts?.pageInfo?.endCursor || null,
2484
+ hasNextPage : Boolean( discounts?.pageInfo?.hasNextPage )
2485
+ }
2486
+ };
2487
+
2488
+ }
2149
2489
  }
2150
2490
  ,
2151
2491
 
@@ -2380,10 +2720,12 @@ var webhook = {
2380
2720
  // connect generates a secret rather than proving a credential.
2381
2721
  hooks : {
2382
2722
  auth : {
2383
- // Minting and clearing a secret needs no vendor call, so the api's own
2384
- // handler does both.
2385
- connect : {},
2386
- disconnect : {},
2723
+ // FALSE, NOT {}. There is no vendor here at all connecting mints a
2724
+ // secret and disconnecting clears it, both done by the api's own
2725
+ // handler. `{}` would promise a body implemented elsewhere, and none
2726
+ // exists or could.
2727
+ connect : false,
2728
+ disconnect : false,
2387
2729
  probe : false,
2388
2730
  scopes : false,
2389
2731
  // Nothing to mint. Connecting generates a secret; there is no vendor.
@@ -2945,6 +3287,7 @@ const stepLabels = ( catalog = connections ) => Object.fromEntries(
2945
3287
  );
2946
3288
 
2947
3289
  const connections = Object.freeze({
3290
+ attentive : build( attentive ),
2948
3291
  drawbridge : build( drawbridge ),
2949
3292
  hubspot : build( hubspot ),
2950
3293
  klaviyo : build( klaviyo ),
@@ -3140,6 +3483,39 @@ const stepQueues = ( env = {} ) => Object.fromEntries(
3140
3483
  connectionSteps( env ).map( ( step ) => [ step.type, step.queue ] )
3141
3484
  );
3142
3485
 
3486
+ // THE WHOLE ROUTING TABLE: live step types plus the retired ones still stored
3487
+ // on workflow documents.
3488
+ //
3489
+ // Both halves were already facts here — stepQueues answers new→queue and
3490
+ // RETIRED answers old→new — but the composition of the two lived in sync as a
3491
+ // hand-written block of `step.shopify.* : 'connection'` literals. That block
3492
+ // and this file had to be edited together and nothing said so, which is the
3493
+ // exact shape of the drift that orphans a queue: retire a step type here,
3494
+ // forget the literal there, and the dispatcher logs unknown-step-type while
3495
+ // the work silently stops.
3496
+ //
3497
+ // A retired type routes wherever its REPLACEMENT routes, because that is what
3498
+ // retiring meant — same work, new name. So there is no second table to keep;
3499
+ // moving a live step to a different queue moves its aliases with it.
3500
+ //
3501
+ // Retired entries whose replacement is not currently live (a vendor gated off
3502
+ // by env) are omitted rather than guessed: no queue exists to route them to,
3503
+ // and a made-up destination is worse than a clean unknown-step-type.
3504
+ const stepRoutes = ( env = {} ) => {
3505
+
3506
+ const live = stepQueues( env );
3507
+
3508
+ return Object.freeze({
3509
+ ...live,
3510
+ ...Object.fromEntries(
3511
+ Object.entries( RETIRED )
3512
+ .filter( ( [ , replacement ] ) => live[ replacement ] )
3513
+ .map( ( [ retired, replacement ] ) => [ retired, live[ replacement ] ] )
3514
+ )
3515
+ });
3516
+
3517
+ };
3518
+
3143
3519
  // Merchant-facing scope-drift copy.
3144
3520
  //
3145
3521
  // THIS IS A CROSS-REPO CONTRACT. drawbridge-sync writes it onto the connection
@@ -3277,4 +3653,4 @@ const resolveConnection = ( item, data, env = {} ) => {
3277
3653
 
3278
3654
  };
3279
3655
 
3280
- export { AUTH_TYPES, GROUPS, HOOKS, HOOK_NAMES, INPUTS, OAUTH_FIELDS, OUTCOMES, RETIRED, STATUSES, STEPS, STEP_TYPES, accessToken, authToken, availableConnections, build, catalogConnections, connectFields, connectionSteps, connections, hookSupport, isStale, mergeSettings, projectConnection, publicConnectionKeys, publicSettingsBySlug, redactSettings, resolveConnection, runHook, scopesMessage, stepLabels, stepQueues, tokenSettings };
3656
+ export { AUTH_TYPES, GROUPS, HOOKS, HOOK_NAMES, INPUTS, OAUTH_FIELDS, OUTCOMES, RETIRED, STATUSES, STEPS, STEP_TYPES, accessToken, authToken, availableConnections, build, catalogConnections, connectFields, connectionSteps, connections, hookSupport, isStale, mergeSettings, projectConnection, publicConnectionKeys, publicSettingsBySlug, redactSettings, resolveConnection, runHook, scopesMessage, stepLabels, stepQueues, stepRoutes, tokenSettings };