@orbit-app/functions 0.4.0 → 0.6.0
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/README.md +3 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +13 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,9 +22,11 @@ export default defineFunction({
|
|
|
22
22
|
});
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
A function can also map a provider account to the store member who connected it, such as the reviewers of a GitLab event: `await orbit.connections.members("gitlab", { accountIds })` gives `{ userId, accountId, username, team }` for each match, and `team` keeps only one Slack workspace or Grid org (0.6.0 and later).
|
|
26
|
+
|
|
25
27
|
Declare each function under `functions` in `orbit.json`. `orbit publish` and `orbit pack` bundle each entry with esbuild and `serve()`, the wrapper of this package. Do not call `serve()` yourself.
|
|
26
28
|
|
|
27
|
-
The full guide (triggers, limits, org connections, the run log) is `functions.md` of the Orbit MCP server's docs. In this repository it is `api/docs/functions.md`.
|
|
29
|
+
The full guide (triggers, limits, org connections, the run log) is `functions.md` of the Orbit MCP server's docs. In this repository it is `api/public-docs/functions.md`.
|
|
28
30
|
|
|
29
31
|
## Develop this package
|
|
30
32
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ObjectsApi, type ObjectsClient } from "@orbit-app/web";
|
|
2
|
-
export { OrbitObjectError, type ObjectsApi, type ObjectsClient } from "@orbit-app/web";
|
|
1
|
+
import { type ObjectsApi, type ObjectsClient, type ObjectsOptions } from "@orbit-app/web";
|
|
2
|
+
export { OrbitObjectError, type ObjectsApi, type ObjectsClient, type ObjectsOptions, type RetryOptions } from "@orbit-app/web";
|
|
3
3
|
export type ActionTrigger = {
|
|
4
4
|
type: "action";
|
|
5
5
|
};
|
|
@@ -105,6 +105,12 @@ export type OrgConnection = {
|
|
|
105
105
|
body?: string | Uint8Array | null;
|
|
106
106
|
}): Promise<Response>;
|
|
107
107
|
};
|
|
108
|
+
export type ConnectionMember = {
|
|
109
|
+
userId: string;
|
|
110
|
+
accountId: string;
|
|
111
|
+
username: string | null;
|
|
112
|
+
team: string | null;
|
|
113
|
+
};
|
|
108
114
|
export interface OrbitSecretNames {
|
|
109
115
|
}
|
|
110
116
|
export type OrbitSecretName = [keyof OrbitSecretNames] extends [never] ? string : Extract<keyof OrbitSecretNames, string>;
|
|
@@ -112,9 +118,13 @@ export type FunctionOrbit = {
|
|
|
112
118
|
objects: ObjectsApi;
|
|
113
119
|
defineObjects<Types extends Record<string, Record<string, unknown>>, Required extends {
|
|
114
120
|
[K in keyof Types]?: keyof Types[K];
|
|
115
|
-
} = {}>(): ObjectsClient<Types, Required>;
|
|
121
|
+
} = {}>(options?: ObjectsOptions): ObjectsClient<Types, Required>;
|
|
116
122
|
connections: {
|
|
117
123
|
get(provider: string): Promise<OrgConnection | null>;
|
|
124
|
+
members(provider: string, opts?: {
|
|
125
|
+
accountIds?: readonly string[];
|
|
126
|
+
team?: string;
|
|
127
|
+
}): Promise<ConnectionMember[]>;
|
|
118
128
|
};
|
|
119
129
|
defineDelegates<M extends Record<string, DelegateTypes> = Record<string, DelegateTypes>>(): Delegates<M>;
|
|
120
130
|
org(): OrbitOrg;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Orbit Functions: publisher code that runs in Orbit's sandbox, never on a member's Mac. A function
|
|
2
2
|
// acts as the store's org. It reaches only the Orbit API, with the token of its run.
|
|
3
|
-
import { OrbitObjectError, typedObjects, } from "@orbit-app/web";
|
|
3
|
+
import { OrbitObjectError, typedObjects, withRetry, } from "@orbit-app/web";
|
|
4
4
|
export { OrbitObjectError } from "@orbit-app/web";
|
|
5
5
|
const DELEGATE_CODES = [
|
|
6
6
|
"invalid",
|
|
@@ -156,7 +156,7 @@ function createOrbit(req) {
|
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
158
|
const enc = encodeURIComponent;
|
|
159
|
-
const
|
|
159
|
+
const once = {
|
|
160
160
|
create: (input) => call("POST", "/v1/objects", input),
|
|
161
161
|
get: (id) => call("GET", `/v1/objects/${enc(id)}`),
|
|
162
162
|
getByHandle: (type, handle) => call("GET", `/v1/objects/by-handle/${enc(type)}/${enc(handle)}`),
|
|
@@ -167,6 +167,7 @@ function createOrbit(req) {
|
|
|
167
167
|
await call("DELETE", `/v1/objects/${enc(id)}`);
|
|
168
168
|
},
|
|
169
169
|
};
|
|
170
|
+
const objects = withRetry(once);
|
|
170
171
|
function connection(c) {
|
|
171
172
|
return Object.freeze({
|
|
172
173
|
provider: c.provider,
|
|
@@ -196,13 +197,22 @@ function createOrbit(req) {
|
|
|
196
197
|
}
|
|
197
198
|
return {
|
|
198
199
|
objects,
|
|
199
|
-
defineObjects: () => typedObjects(objects),
|
|
200
|
+
defineObjects: (options) => typedObjects(options ? withRetry(once, options.retry) : objects),
|
|
200
201
|
connections: {
|
|
201
202
|
async get(provider) {
|
|
202
203
|
const list = (await call("GET", "/v1/connections?owner=org"));
|
|
203
204
|
const c = list.connections.find((x) => x.provider === provider && x.status === "active");
|
|
204
205
|
return c ? connection(c) : null;
|
|
205
206
|
},
|
|
207
|
+
async members(provider, opts = {}) {
|
|
208
|
+
const ids = opts.accountIds ? [...opts.accountIds] : undefined;
|
|
209
|
+
if (ids?.length === 0)
|
|
210
|
+
return [];
|
|
211
|
+
const params = [...(ids ?? []).map((id) => `accountId=${enc(String(id))}`), ...(opts.team ? [`team=${enc(opts.team)}`] : [])];
|
|
212
|
+
const query = params.length ? `?${params.join("&")}` : "";
|
|
213
|
+
const reply = (await call("GET", `/v1/connections/${enc(provider)}/members${query}`));
|
|
214
|
+
return reply.members.map((m) => Object.freeze({ userId: m.userId, accountId: m.accountId, username: m.username ?? null, team: m.team ?? null }));
|
|
215
|
+
},
|
|
206
216
|
},
|
|
207
217
|
defineDelegates: () => ({
|
|
208
218
|
sign: (name, opts) => call("POST", "/v1/delegates", { name, ...opts }, delegateError),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbit-app/functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Write Orbit Functions: publisher code that runs in Orbit's sandbox as the store's org.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"prepack": "pnpm build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@orbit-app/web": "^0.1.
|
|
22
|
+
"@orbit-app/web": "^0.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "^7.0.2",
|