@inixiative/integrations 0.4.0 → 0.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inixiative/integrations",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "The provider catalog behind Kingdom integrations: each provider's operations, events, resource kinds and scopes, with the request, webhook and credential code that reaches it.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -0,0 +1,12 @@
1
+ import type { IntegrationFamily, Provider } from '../contracts';
2
+ import { findProvider } from './findProvider';
3
+ import { integrationFamilyDefinition } from './integrationFamilyDefinition';
4
+
5
+ export const refreshTokenRotates = (
6
+ owner: { provider: Provider } | { integrationFamily: IntegrationFamily },
7
+ ) => {
8
+ // why: an unknown refresh outcome may have spent a rotating token, so only a non-rotating one is safe to retry.
9
+ if ('integrationFamily' in owner)
10
+ return integrationFamilyDefinition(owner.integrationFamily)?.oauth?.refreshTokenRotates ?? true;
11
+ return findProvider(owner.provider)?.refreshTokenRotates ?? true;
12
+ };
package/src/contracts.ts CHANGED
@@ -83,7 +83,9 @@ export const integrationFamilyDefinitionSchema = z
83
83
  name: z.string(),
84
84
  documentationUrl: z.url(),
85
85
  authMethods: z.array(credentialMethodSchema),
86
- oauth: z.object({ authorizeUrl: z.url(), tokenUrl: z.url() }).optional(),
86
+ oauth: z
87
+ .object({ authorizeUrl: z.url(), tokenUrl: z.url(), refreshTokenRotates: z.boolean() })
88
+ .optional(),
87
89
  })
88
90
  .refine((definition) => !definition.authMethods.includes('oauth2') || definition.oauth, {
89
91
  message: 'an integration family with oauth2 auth needs its OAuth endpoints',
@@ -102,6 +104,7 @@ export const providerDefinitionSchema = z
102
104
  subscription: z.boolean().optional(),
103
105
  integrationFamily: integrationFamilySchema.optional(),
104
106
  oauthScopes: z.array(z.string()).optional(),
107
+ refreshTokenRotates: z.boolean().optional(),
105
108
  })
106
109
  .refine(
107
110
  (definition) =>
@@ -8,5 +8,6 @@ export const atlassianIntegrationFamily: IntegrationFamilyDefinition = {
8
8
  oauth: {
9
9
  authorizeUrl: 'https://auth.atlassian.com/authorize',
10
10
  tokenUrl: 'https://auth.atlassian.com/oauth/token',
11
+ refreshTokenRotates: true,
11
12
  },
12
13
  };
@@ -8,5 +8,6 @@ export const githubIntegrationFamily: IntegrationFamilyDefinition = {
8
8
  oauth: {
9
9
  authorizeUrl: 'https://github.com/login/oauth/authorize',
10
10
  tokenUrl: 'https://github.com/login/oauth/access_token',
11
+ refreshTokenRotates: true,
11
12
  },
12
13
  };
@@ -8,5 +8,6 @@ export const googleIntegrationFamily: IntegrationFamilyDefinition = {
8
8
  oauth: {
9
9
  authorizeUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
10
10
  tokenUrl: 'https://oauth2.googleapis.com/token',
11
+ refreshTokenRotates: false,
11
12
  },
12
13
  };