@agentworkforce/sage 1.2.2 → 1.2.3

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/dist/nango.d.ts CHANGED
@@ -38,6 +38,5 @@ export declare class NangoClient {
38
38
  proxy<T>(config: ProxyConfig): Promise<T>;
39
39
  getConnection(connectionId: string, providerConfigKey: string): Promise<NangoConnection | null>;
40
40
  discoverGitHubOrgs(connectionId: string, providerConfigKey: string): Promise<GitHubOrgDiscovery>;
41
- private listGitHubInstallationRepos;
42
41
  }
43
42
  //# sourceMappingURL=nango.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nango.d.ts","sourceRoot":"","sources":["../src/nango.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAC9B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C5B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAC9B;AAgBD,qBAAa,UAAW,SAAQ,KAAK;aAEjB,SAAS,EAAE,MAAM;aACjB,MAAM,EAAE,MAAM;aACd,KAAK,EAAE,OAAO;gBAFd,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO;CAKjC;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAqD;IAC7F,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAIhD,OAAO,CAAC,SAAS;IAIX,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAQzC,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAQ/F,kBAAkB,CACtB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,kBAAkB,CAAC;CAgF/B"}
package/dist/nango.js CHANGED
@@ -45,31 +45,50 @@ export class NangoClient {
45
45
  if (cached && cached.expiresAt > Date.now()) {
46
46
  return cloneGitHubOrgDiscovery(cached.value);
47
47
  }
48
- const response = await this.proxy({
49
- connectionId,
50
- providerConfigKey: resolvedProviderConfigKey,
51
- method: 'GET',
52
- endpoint: '/user/installations',
53
- });
48
+ // https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#list-repositories-accessible-to-the-app-installation
49
+ const allRepos = [];
50
+ let page = 1;
51
+ const perPage = 100;
52
+ while (true) {
53
+ const response = await this.proxy({
54
+ connectionId,
55
+ providerConfigKey: resolvedProviderConfigKey,
56
+ method: 'GET',
57
+ endpoint: `/installation/repositories?per_page=${perPage}&page=${page}`,
58
+ });
59
+ const repos = response.repositories ?? [];
60
+ allRepos.push(...repos);
61
+ if (repos.length < perPage) {
62
+ break;
63
+ }
64
+ page++;
65
+ if (page > 10) {
66
+ break; // Safety limit
67
+ }
68
+ }
54
69
  const orgs = new Set();
55
70
  const reposByOrg = new Map();
56
- for (const installation of response.installations ?? []) {
57
- const org = installation.account?.login?.trim();
58
- if (!org) {
71
+ for (const repo of allRepos) {
72
+ const fullName = repo.full_name?.trim();
73
+ if (!fullName) {
59
74
  continue;
60
75
  }
61
- orgs.add(org);
62
- const repoNames = await this.listGitHubInstallationRepos(connectionId, resolvedProviderConfigKey, installation);
63
- if (!reposByOrg.has(org)) {
64
- reposByOrg.set(org, new Set());
76
+ const slashIndex = fullName.indexOf('/');
77
+ if (slashIndex <= 0) {
78
+ continue;
65
79
  }
66
- const orgRepos = reposByOrg.get(org);
67
- if (!orgRepos) {
80
+ const org = fullName.slice(0, slashIndex);
81
+ const repoName = fullName.slice(slashIndex + 1);
82
+ if (!org || !repoName) {
68
83
  continue;
69
84
  }
70
- for (const repoName of repoNames) {
71
- orgRepos.add(repoName);
85
+ orgs.add(org);
86
+ let orgRepos = reposByOrg.get(org);
87
+ if (!orgRepos) {
88
+ orgRepos = new Set();
89
+ reposByOrg.set(org, orgRepos);
72
90
  }
91
+ orgRepos.add(repoName);
73
92
  }
74
93
  const value = {
75
94
  orgs: [...orgs].sort((left, right) => left.localeCompare(right)),
@@ -83,81 +102,6 @@ export class NangoClient {
83
102
  });
84
103
  return cloneGitHubOrgDiscovery(value);
85
104
  }
86
- async listGitHubInstallationRepos(connectionId, providerConfigKey, installation) {
87
- const endpoints = buildGitHubInstallationRepoEndpoints(installation);
88
- if (endpoints.length === 0) {
89
- return [];
90
- }
91
- let lastError;
92
- for (const endpoint of endpoints) {
93
- try {
94
- // Paginate through all pages (GitHub returns max 30 per page)
95
- const allRepos = [];
96
- let page = 1;
97
- const perPage = 100;
98
- while (true) {
99
- const separator = endpoint.includes('?') ? '&' : '?';
100
- const pagedEndpoint = `${endpoint}${separator}per_page=${perPage}&page=${page}`;
101
- const response = await this.proxy({
102
- connectionId,
103
- providerConfigKey,
104
- method: 'GET',
105
- endpoint: pagedEndpoint,
106
- });
107
- const repos = response.repositories ?? [];
108
- allRepos.push(...normalizeGitHubRepoNames(repos));
109
- if (repos.length < perPage) {
110
- break; // Last page
111
- }
112
- page++;
113
- if (page > 10) {
114
- break; // Safety limit
115
- }
116
- }
117
- return allRepos;
118
- }
119
- catch (error) {
120
- lastError = error;
121
- }
122
- }
123
- throw new NangoError('discoverGitHubOrgs', installation.account?.login?.trim() || connectionId, lastError ?? new Error('GitHub installation repositories request failed'));
124
- }
125
- }
126
- function buildGitHubInstallationRepoEndpoints(installation) {
127
- const endpoints = new Set();
128
- if (typeof installation.id === 'number') {
129
- endpoints.add(`/user/installations/${installation.id}/repositories`);
130
- }
131
- const repositoriesPath = extractGitHubApiPath(installation.repositories_url);
132
- if (repositoriesPath) {
133
- endpoints.add(repositoriesPath);
134
- }
135
- return [...endpoints];
136
- }
137
- function extractGitHubApiPath(url) {
138
- if (!url) {
139
- return null;
140
- }
141
- if (url.startsWith('/')) {
142
- return url;
143
- }
144
- try {
145
- const parsed = new URL(url);
146
- return `${parsed.pathname}${parsed.search}`;
147
- }
148
- catch {
149
- return null;
150
- }
151
- }
152
- function normalizeGitHubRepoNames(repositories) {
153
- const names = new Set();
154
- for (const repository of repositories) {
155
- const repoName = repository.name?.trim() || repository.full_name?.split('/').pop()?.trim();
156
- if (repoName) {
157
- names.add(repoName);
158
- }
159
- }
160
- return [...names].sort((left, right) => left.localeCompare(right));
161
105
  }
162
106
  function cloneGitHubOrgDiscovery(discovery) {
163
107
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentworkforce/sage",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/AgentWorkforce/sage.git"