@drawbridge/drawbridge-utils 0.0.174 → 0.0.176

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.
@@ -43,9 +43,9 @@ var pkcePair = () => {
43
43
  var consentUrl = ({ challenge, clientId, descriptor, redirect, state } = {}) => {
44
44
  var _a;
45
45
  if (!clientId) throw new Error("This deployment has no OAuth client configured, so there is nothing to consent through");
46
- if (!((_a = descriptor == null ? void 0 : descriptor.urls) == null ? void 0 : _a.authorize)) throw new Error("This connection declares no authorize url");
46
+ if (!((_a = descriptor == null ? void 0 : descriptor.endpoints) == null ? void 0 : _a.authorize)) throw new Error("This connection declares no authorize endpoint");
47
47
  if (descriptor.pkce && !challenge) throw new Error("This connection requires PKCE, so a code challenge is not optional");
48
- return descriptor.urls.authorize + "?" + new URLSearchParams({
48
+ return descriptor.endpoints.authorize + "?" + new URLSearchParams({
49
49
  // The descriptor's own params go FIRST, so a vendor quirk cannot quietly
50
50
  // overwrite one of the fields below that every consent carries.
51
51
  ...descriptor.params || {},
@@ -73,12 +73,12 @@ var authToken = async ({
73
73
  } = {}) => {
74
74
  var _a;
75
75
  if (!clientId || !clientSecret) throw new Error("This deployment has no OAuth client configured, so no token can be minted");
76
- if (!((_a = descriptor == null ? void 0 : descriptor.urls) == null ? void 0 : _a.token)) throw new Error("This connection declares no token url");
76
+ if (!((_a = descriptor == null ? void 0 : descriptor.endpoints) == null ? void 0 : _a.token)) throw new Error("This connection declares no token endpoint");
77
77
  const renewing = !code;
78
78
  if (renewing && !refreshToken) throw new Error("Nothing has been consented to yet, so there is no refresh token to spend");
79
79
  if (!renewing && descriptor.pkce && !verifier) throw new Error("This connection requires PKCE, so the code verifier is not optional");
80
80
  const client = credentials({ basic, clientId, clientSecret });
81
- const response = await fetcher(descriptor.urls.token, {
81
+ const response = await fetcher(descriptor.endpoints.token, {
82
82
  body: new URLSearchParams({
83
83
  ...client.body,
84
84
  ...renewing ? { grant_type: "refresh_token", refresh_token: refreshToken } : {
@@ -34,18 +34,20 @@ const credentials = ({ basic, clientId, clientSecret }) => (
34
34
  // hand-written, so a second one copies every line.
35
35
  //
36
36
  // auth : {
37
- // type : 'oauth',
37
+ // generated : false, install : false, keys : false, none : false,
38
38
  // oauth : {
39
- // urls : { authorize : 'https://login.mailchimp.com/oauth2/authorize',
40
39
  // client : { id : 'MAILCHIMP_OAUTH_CLIENT_ID', secret : 'MAILCHIMP_OAUTH_CLIENT_SECRET' },
41
- // redirect : '/api/connection/mailchimp/callback',
42
- // token : 'https://login.mailchimp.com/oauth2/token',
40
+ // endpoints : { authorize : 'https://login.mailchimp.com/oauth2/authorize',
41
+ // token : 'https://login.mailchimp.com/oauth2/token' },
43
42
  // params : { ... }, optional vendor quirks
44
43
  // pkce : true, Klaviyo's OAuth 2.1 requires it
45
44
  // scopes : '...' optional; Mailchimp has none
46
45
  // }
47
46
  // }
48
47
  //
48
+ // The SHAPE says which kind it is — exactly one of the five non-false — and
49
+ // build() injects auth.type and auth.oauth.callback from it.
50
+ //
49
51
  // NO CREDENTIAL LIVES HERE OR IN A MANIFEST. `client` NAMES the environment
50
52
  // variables holding OUR application's client — one identity, every merchant,
51
53
  // which is what an OAuth client is. The token belongs to the merchant and
@@ -83,11 +85,11 @@ const consentUrl = ({ challenge, clientId, descriptor, redirect, state } = {}) =
83
85
  // fault nobody can fix from a connection page.
84
86
  if( ! clientId ) throw new Error( 'This deployment has no OAuth client configured, so there is nothing to consent through' );
85
87
 
86
- if( ! descriptor?.urls?.authorize ) throw new Error( 'This connection declares no authorize url' );
88
+ if( ! descriptor?.endpoints?.authorize ) throw new Error( 'This connection declares no authorize endpoint' );
87
89
 
88
90
  if( descriptor.pkce && ! challenge ) throw new Error( 'This connection requires PKCE, so a code challenge is not optional' );
89
91
 
90
- return descriptor.urls.authorize + '?' + new URLSearchParams({
92
+ return descriptor.endpoints.authorize + '?' + new URLSearchParams({
91
93
  // The descriptor's own params go FIRST, so a vendor quirk cannot quietly
92
94
  // overwrite one of the fields below that every consent carries.
93
95
  ...( descriptor.params || {} ),
@@ -139,7 +141,7 @@ const authToken = async ({
139
141
  } = {}) => {
140
142
 
141
143
  if( ! clientId || ! clientSecret ) throw new Error( 'This deployment has no OAuth client configured, so no token can be minted' );
142
- if( ! descriptor?.urls?.token ) throw new Error( 'This connection declares no token url' );
144
+ if( ! descriptor?.endpoints?.token ) throw new Error( 'This connection declares no token endpoint' );
143
145
 
144
146
  const renewing = ! code;
145
147
 
@@ -148,7 +150,7 @@ const authToken = async ({
148
150
 
149
151
  const client = credentials({ basic, clientId, clientSecret });
150
152
 
151
- const response = await fetcher( descriptor.urls.token, {
153
+ const response = await fetcher( descriptor.endpoints.token, {
152
154
  body : new URLSearchParams({
153
155
  ...client.body,
154
156
  ...( renewing
@@ -34,18 +34,20 @@ const credentials = ({ basic, clientId, clientSecret }) => (
34
34
  // hand-written, so a second one copies every line.
35
35
  //
36
36
  // auth : {
37
- // type : 'oauth',
37
+ // generated : false, install : false, keys : false, none : false,
38
38
  // oauth : {
39
- // urls : { authorize : 'https://login.mailchimp.com/oauth2/authorize',
40
39
  // client : { id : 'MAILCHIMP_OAUTH_CLIENT_ID', secret : 'MAILCHIMP_OAUTH_CLIENT_SECRET' },
41
- // redirect : '/api/connection/mailchimp/callback',
42
- // token : 'https://login.mailchimp.com/oauth2/token',
40
+ // endpoints : { authorize : 'https://login.mailchimp.com/oauth2/authorize',
41
+ // token : 'https://login.mailchimp.com/oauth2/token' },
43
42
  // params : { ... }, optional vendor quirks
44
43
  // pkce : true, Klaviyo's OAuth 2.1 requires it
45
44
  // scopes : '...' optional; Mailchimp has none
46
45
  // }
47
46
  // }
48
47
  //
48
+ // The SHAPE says which kind it is — exactly one of the five non-false — and
49
+ // build() injects auth.type and auth.oauth.callback from it.
50
+ //
49
51
  // NO CREDENTIAL LIVES HERE OR IN A MANIFEST. `client` NAMES the environment
50
52
  // variables holding OUR application's client — one identity, every merchant,
51
53
  // which is what an OAuth client is. The token belongs to the merchant and
@@ -83,11 +85,11 @@ const consentUrl = ({ challenge, clientId, descriptor, redirect, state } = {}) =
83
85
  // fault nobody can fix from a connection page.
84
86
  if( ! clientId ) throw new Error( 'This deployment has no OAuth client configured, so there is nothing to consent through' );
85
87
 
86
- if( ! descriptor?.urls?.authorize ) throw new Error( 'This connection declares no authorize url' );
88
+ if( ! descriptor?.endpoints?.authorize ) throw new Error( 'This connection declares no authorize endpoint' );
87
89
 
88
90
  if( descriptor.pkce && ! challenge ) throw new Error( 'This connection requires PKCE, so a code challenge is not optional' );
89
91
 
90
- return descriptor.urls.authorize + '?' + new URLSearchParams({
92
+ return descriptor.endpoints.authorize + '?' + new URLSearchParams({
91
93
  // The descriptor's own params go FIRST, so a vendor quirk cannot quietly
92
94
  // overwrite one of the fields below that every consent carries.
93
95
  ...( descriptor.params || {} ),
@@ -139,7 +141,7 @@ const authToken = async ({
139
141
  } = {}) => {
140
142
 
141
143
  if( ! clientId || ! clientSecret ) throw new Error( 'This deployment has no OAuth client configured, so no token can be minted' );
142
- if( ! descriptor?.urls?.token ) throw new Error( 'This connection declares no token url' );
144
+ if( ! descriptor?.endpoints?.token ) throw new Error( 'This connection declares no token endpoint' );
143
145
 
144
146
  const renewing = ! code;
145
147
 
@@ -148,7 +150,7 @@ const authToken = async ({
148
150
 
149
151
  const client = credentials({ basic, clientId, clientSecret });
150
152
 
151
- const response = await fetcher( descriptor.urls.token, {
153
+ const response = await fetcher( descriptor.endpoints.token, {
152
154
  body : new URLSearchParams({
153
155
  ...client.body,
154
156
  ...( renewing
@@ -18,9 +18,9 @@ var pkcePair = () => {
18
18
  var consentUrl = ({ challenge, clientId, descriptor, redirect, state } = {}) => {
19
19
  var _a;
20
20
  if (!clientId) throw new Error("This deployment has no OAuth client configured, so there is nothing to consent through");
21
- if (!((_a = descriptor == null ? void 0 : descriptor.urls) == null ? void 0 : _a.authorize)) throw new Error("This connection declares no authorize url");
21
+ if (!((_a = descriptor == null ? void 0 : descriptor.endpoints) == null ? void 0 : _a.authorize)) throw new Error("This connection declares no authorize endpoint");
22
22
  if (descriptor.pkce && !challenge) throw new Error("This connection requires PKCE, so a code challenge is not optional");
23
- return descriptor.urls.authorize + "?" + new URLSearchParams({
23
+ return descriptor.endpoints.authorize + "?" + new URLSearchParams({
24
24
  // The descriptor's own params go FIRST, so a vendor quirk cannot quietly
25
25
  // overwrite one of the fields below that every consent carries.
26
26
  ...descriptor.params || {},
@@ -48,12 +48,12 @@ var authToken = async ({
48
48
  } = {}) => {
49
49
  var _a;
50
50
  if (!clientId || !clientSecret) throw new Error("This deployment has no OAuth client configured, so no token can be minted");
51
- if (!((_a = descriptor == null ? void 0 : descriptor.urls) == null ? void 0 : _a.token)) throw new Error("This connection declares no token url");
51
+ if (!((_a = descriptor == null ? void 0 : descriptor.endpoints) == null ? void 0 : _a.token)) throw new Error("This connection declares no token endpoint");
52
52
  const renewing = !code;
53
53
  if (renewing && !refreshToken) throw new Error("Nothing has been consented to yet, so there is no refresh token to spend");
54
54
  if (!renewing && descriptor.pkce && !verifier) throw new Error("This connection requires PKCE, so the code verifier is not optional");
55
55
  const client = credentials({ basic, clientId, clientSecret });
56
- const response = await fetcher(descriptor.urls.token, {
56
+ const response = await fetcher(descriptor.endpoints.token, {
57
57
  body: new URLSearchParams({
58
58
  ...client.body,
59
59
  ...renewing ? { grant_type: "refresh_token", refresh_token: refreshToken } : {