@orbit-app/functions 0.2.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -91,6 +91,9 @@ export type OrgConnection = {
91
91
  body?: string | Uint8Array | null;
92
92
  }): Promise<Response>;
93
93
  };
94
+ export interface OrbitSecretNames {
95
+ }
96
+ export type OrbitSecretName = [keyof OrbitSecretNames] extends [never] ? string : Extract<keyof OrbitSecretNames, string>;
94
97
  export type FunctionOrbit = {
95
98
  objects: ObjectsApi;
96
99
  defineObjects<Types extends Record<string, Record<string, unknown>>, Required extends {
@@ -101,6 +104,7 @@ export type FunctionOrbit = {
101
104
  };
102
105
  defineDelegates<M extends Record<string, DelegateTypes> = Record<string, DelegateTypes>>(): Delegates<M>;
103
106
  org(): OrbitOrg;
107
+ secret(name: OrbitSecretName): string;
104
108
  };
105
109
  export type ActionFunction<Input = unknown, Output = unknown> = {
106
110
  trigger: ActionTrigger;
@@ -136,6 +140,7 @@ export type DispatchRequest = {
136
140
  attempt?: number;
137
141
  delegate?: DelegateContext["delegate"];
138
142
  org: OrbitOrg;
143
+ secretNonce?: string;
139
144
  };
140
145
  };
141
146
  export type DispatchReply = {
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ export class OrbitDelegateError extends Error {
28
28
  this.retryAfter = extra.retryAfter;
29
29
  }
30
30
  }
31
+ const SECRET_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
31
32
  export function defineFunction(def) {
32
33
  return def;
33
34
  }
@@ -202,6 +203,15 @@ function createOrbit(req) {
202
203
  },
203
204
  }),
204
205
  org: () => ({ ...req.ctx.org }),
206
+ secret: (name) => {
207
+ if (typeof name !== "string" || !SECRET_NAME.test(name)) {
208
+ throw new Error(`the secret name ${String(name)} must be 1 to 64 characters of A-Z 0-9 _ and start with a letter`);
209
+ }
210
+ const nonce = req.ctx.secretNonce;
211
+ if (typeof nonce !== "string" || !/^[0-9a-f]{32}$/.test(nonce))
212
+ throw new Error("this server gives functions no secrets");
213
+ return `{{orbit:${name}:${nonce}}}`;
214
+ },
205
215
  };
206
216
  }
207
217
  // "/users.info?user=U1" → the path and a query map, as the proxy takes them.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbit-app/functions",
3
- "version": "0.2.0",
3
+ "version": "0.3.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": {