@foir/sdk 0.22.0 → 0.24.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/CHANGELOG.md +230 -154
- package/README.md +6 -6
- package/dist/app/client.d.ts +5 -4
- package/dist/app/contract/proto/apps/v1/apps_pb.d.ts +104 -99
- package/dist/app/contract/proto/apps/v1/discovery_pb.d.ts +10 -10
- package/dist/app/errors.d.ts +8 -6
- package/dist/auth/auth.d.ts +56 -17
- package/dist/auth/grant-table.generated.d.ts +5 -4
- package/dist/auth/hosted.d.ts +29 -0
- package/dist/auth/index.d.ts +4 -4
- package/dist/auth/operations.d.ts +34 -11
- package/dist/auth/ops.d.ts +0 -1
- package/dist/auth/session-client.d.ts +5 -0
- package/dist/auth-session.js +3 -2
- package/dist/auth.js +182 -132
- package/dist/client.js +1 -4
- package/dist/codegen/preset.d.ts +1 -1
- package/dist/components/EditorProvider.d.ts +1 -1
- package/dist/data/client.d.ts +1 -1
- package/dist/data/schema.d.ts +1 -1
- package/dist/data/transport.d.ts +7 -6
- package/dist/data.js +2 -5
- package/dist/index.js +1 -4
- package/dist/next.js +1 -5
- package/dist/placement.js +124 -116
- package/dist/push.js +1 -5
- package/dist/react/FoirProvider.d.ts +1 -1
- package/dist/react/feedback-notes.d.ts +4 -2
- package/dist/react.js +128 -123
- package/dist/server/events-client.d.ts +9 -9
- package/dist/server/types.d.ts +1 -1
- package/dist/server.js +123 -122
- package/dist/transport/foir-http.d.ts +1 -1
- package/dist/transport/key-kind.d.ts +1 -12
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -74,123 +74,123 @@ async function verifyWebhookSignature(payload, signature, secret) {
|
|
|
74
74
|
|
|
75
75
|
// src/auth/grant-table.generated.ts
|
|
76
76
|
var GRANT_TABLE = [
|
|
77
|
-
["records:read",
|
|
78
|
-
["records:create",
|
|
79
|
-
["records:write",
|
|
80
|
-
["records:delete",
|
|
81
|
-
["records:publish",
|
|
82
|
-
["records:attribute",
|
|
83
|
-
["search:read",
|
|
84
|
-
["embeddings:read",
|
|
85
|
-
["embeddings:write",
|
|
86
|
-
["schemas:read",
|
|
87
|
-
["drafts:read",
|
|
88
|
-
["files:read",
|
|
89
|
-
["files:write",
|
|
90
|
-
["files:delete",
|
|
91
|
-
["notifications:read",
|
|
92
|
-
["notifications:write",
|
|
93
|
-
["notifications:consent",
|
|
94
|
-
["pushcredentials:read",
|
|
95
|
-
["pushcredentials:write",
|
|
96
|
-
["notes:read",
|
|
97
|
-
["notes:write",
|
|
98
|
-
["notes:create",
|
|
99
|
-
["approvals:read",
|
|
100
|
-
["approvals:write",
|
|
101
|
-
["rooms:read",
|
|
102
|
-
["rooms:write",
|
|
103
|
-
["presence:read",
|
|
104
|
-
["operations:read",
|
|
105
|
-
["operations:execute",
|
|
106
|
-
["operations:write",
|
|
107
|
-
["operations:complete",
|
|
108
|
-
["status:write",
|
|
109
|
-
["appconfig:read",
|
|
110
|
-
["schedules:read",
|
|
111
|
-
["schedules:write",
|
|
112
|
-
["hooks:read",
|
|
113
|
-
["hooks:write",
|
|
114
|
-
["
|
|
115
|
-
["
|
|
116
|
-
["domains:read",
|
|
117
|
-
["domains:write",
|
|
118
|
-
["secrets:read",
|
|
119
|
-
["secrets:list",
|
|
120
|
-
["secrets:put",
|
|
121
|
-
["secrets:delete",
|
|
122
|
-
["appsecrets:read",
|
|
123
|
-
["appsecrets:list",
|
|
124
|
-
["appsecrets:put",
|
|
125
|
-
["appsecrets:delete",
|
|
126
|
-
["opsecrets:read",
|
|
127
|
-
["opsecrets:write",
|
|
128
|
-
["settings:read",
|
|
129
|
-
["settings:write",
|
|
130
|
-
["designtokens:read",
|
|
131
|
-
["designtokens:write",
|
|
132
|
-
["models:read",
|
|
133
|
-
["models:write",
|
|
134
|
-
["configs:read",
|
|
135
|
-
["configs:write",
|
|
136
|
-
["apps:read",
|
|
137
|
-
["apps:write",
|
|
138
|
-
["events:read",
|
|
139
|
-
["targeting:debug",
|
|
140
|
-
["visitors:forward",
|
|
141
|
-
["apikeys:read",
|
|
142
|
-
["apikeys:write",
|
|
143
|
-
["organizations:read",
|
|
144
|
-
["organizations:write",
|
|
145
|
-
["organizations:create",
|
|
146
|
-
["organizations:delete",
|
|
147
|
-
["organizations:reach",
|
|
148
|
-
["members:read",
|
|
149
|
-
["members:write",
|
|
150
|
-
["roles:read",
|
|
151
|
-
["roles:write",
|
|
152
|
-
["projects:read",
|
|
153
|
-
["projects:write",
|
|
154
|
-
["project:stand",
|
|
155
|
-
["project:manage",
|
|
156
|
-
["projects:create",
|
|
157
|
-
["projects:delete",
|
|
158
|
-
["tenants:read",
|
|
159
|
-
["tenants:write",
|
|
160
|
-
["tenants:delete",
|
|
161
|
-
["audit:read",
|
|
162
|
-
["export:run",
|
|
163
|
-
["billing:read",
|
|
164
|
-
["billing:manage",
|
|
165
|
-
["usage:read",
|
|
166
|
-
["controlkeys:read",
|
|
167
|
-
["controlkeys:write",
|
|
168
|
-
["
|
|
169
|
-
["
|
|
170
|
-
["
|
|
171
|
-
["
|
|
172
|
-
["
|
|
173
|
-
["
|
|
174
|
-
["platform:
|
|
175
|
-
["
|
|
176
|
-
["
|
|
177
|
-
["users:
|
|
178
|
-
["users:
|
|
179
|
-
["users:
|
|
180
|
-
["
|
|
181
|
-
["
|
|
182
|
-
["
|
|
183
|
-
["
|
|
184
|
-
["usersecrets:
|
|
185
|
-
["usersecrets:
|
|
186
|
-
["
|
|
187
|
-
["
|
|
188
|
-
["
|
|
189
|
-
["signinproviders:read", false, [], []],
|
|
190
|
-
["signinproviders:write", false, [], []]
|
|
77
|
+
["records:read", "model", ["own", "all"], []],
|
|
78
|
+
["records:create", "model", [], []],
|
|
79
|
+
["records:write", "model", ["own", "all"], []],
|
|
80
|
+
["records:delete", "model", ["own", "all"], []],
|
|
81
|
+
["records:publish", "model", ["own", "all"], []],
|
|
82
|
+
["records:attribute", "model", [], []],
|
|
83
|
+
["search:read", "model", [], []],
|
|
84
|
+
["embeddings:read", "none", [], []],
|
|
85
|
+
["embeddings:write", "none", [], []],
|
|
86
|
+
["schemas:read", "none", [], []],
|
|
87
|
+
["drafts:read", "none", [], []],
|
|
88
|
+
["files:read", "none", ["own", "all"], []],
|
|
89
|
+
["files:write", "none", ["own", "all"], []],
|
|
90
|
+
["files:delete", "none", ["own", "all"], []],
|
|
91
|
+
["notifications:read", "none", ["own", "all"], []],
|
|
92
|
+
["notifications:write", "none", ["own", "named", "all"], []],
|
|
93
|
+
["notifications:consent", "none", [], []],
|
|
94
|
+
["pushcredentials:read", "none", [], []],
|
|
95
|
+
["pushcredentials:write", "none", [], []],
|
|
96
|
+
["notes:read", "none", ["own", "all"], []],
|
|
97
|
+
["notes:write", "none", ["own", "all"], []],
|
|
98
|
+
["notes:create", "none", [], []],
|
|
99
|
+
["approvals:read", "none", [], []],
|
|
100
|
+
["approvals:write", "none", [], []],
|
|
101
|
+
["rooms:read", "model", [], []],
|
|
102
|
+
["rooms:write", "model", [], []],
|
|
103
|
+
["presence:read", "model", [], []],
|
|
104
|
+
["operations:read", "none", [], []],
|
|
105
|
+
["operations:execute", "operation", [], []],
|
|
106
|
+
["operations:write", "none", [], []],
|
|
107
|
+
["operations:complete", "none", [], []],
|
|
108
|
+
["status:write", "none", [], []],
|
|
109
|
+
["appconfig:read", "none", [], []],
|
|
110
|
+
["schedules:read", "none", [], []],
|
|
111
|
+
["schedules:write", "none", [], []],
|
|
112
|
+
["hooks:read", "none", [], []],
|
|
113
|
+
["hooks:write", "none", [], []],
|
|
114
|
+
["authclients:read", "none", [], []],
|
|
115
|
+
["authclients:write", "none", [], []],
|
|
116
|
+
["domains:read", "none", [], []],
|
|
117
|
+
["domains:write", "none", [], []],
|
|
118
|
+
["secrets:read", "none", [], []],
|
|
119
|
+
["secrets:list", "none", [], []],
|
|
120
|
+
["secrets:put", "none", [], []],
|
|
121
|
+
["secrets:delete", "none", [], []],
|
|
122
|
+
["appsecrets:read", "none", [], []],
|
|
123
|
+
["appsecrets:list", "none", [], []],
|
|
124
|
+
["appsecrets:put", "none", [], []],
|
|
125
|
+
["appsecrets:delete", "none", [], []],
|
|
126
|
+
["opsecrets:read", "none", [], []],
|
|
127
|
+
["opsecrets:write", "none", [], []],
|
|
128
|
+
["settings:read", "none", [], []],
|
|
129
|
+
["settings:write", "none", [], []],
|
|
130
|
+
["designtokens:read", "none", [], []],
|
|
131
|
+
["designtokens:write", "none", [], []],
|
|
132
|
+
["models:read", "none", [], []],
|
|
133
|
+
["models:write", "none", [], []],
|
|
134
|
+
["configs:read", "none", [], []],
|
|
135
|
+
["configs:write", "none", [], []],
|
|
136
|
+
["apps:read", "none", [], []],
|
|
137
|
+
["apps:write", "none", [], []],
|
|
138
|
+
["events:read", "none", [], []],
|
|
139
|
+
["targeting:debug", "none", [], []],
|
|
140
|
+
["visitors:forward", "none", [], []],
|
|
141
|
+
["apikeys:read", "none", [], []],
|
|
142
|
+
["apikeys:write", "none", [], []],
|
|
143
|
+
["organizations:read", "none", [], []],
|
|
144
|
+
["organizations:write", "none", [], []],
|
|
145
|
+
["organizations:create", "none", [], []],
|
|
146
|
+
["organizations:delete", "none", [], []],
|
|
147
|
+
["organizations:reach", "none", [], []],
|
|
148
|
+
["members:read", "none", [], []],
|
|
149
|
+
["members:write", "none", [], []],
|
|
150
|
+
["roles:read", "none", [], []],
|
|
151
|
+
["roles:write", "none", [], []],
|
|
152
|
+
["projects:read", "none", [], []],
|
|
153
|
+
["projects:write", "none", [], []],
|
|
154
|
+
["project:stand", "none", [], []],
|
|
155
|
+
["project:manage", "none", [], ["project:stand", "records:read.all", "records:create", "records:write.all", "records:delete.all", "records:publish.all", "records:attribute", "search:read", "embeddings:read", "embeddings:write", "schemas:read", "drafts:read", "files:read.all", "files:write.all", "files:delete.all", "users:read.all", "identities:read", "users:create", "identities:delete", "users:write.all", "users:setup", "users:delete.all", "notifications:read.all", "notifications:write.all", "notifications:consent", "pushcredentials:read", "pushcredentials:write", "notes:read.all", "notes:write.all", "notes:create", "approvals:read", "approvals:write", "rooms:read", "rooms:write", "presence:read", "operations:read", "operations:execute", "operations:write", "appconfig:read", "schedules:read", "schedules:write", "hooks:read", "hooks:write", "auth:login_with_foir", "authclients:read", "authclients:write", "domains:read", "domains:write", "secrets:read", "secrets:list", "secrets:put", "secrets:delete", "appsecrets:read", "appsecrets:list", "appsecrets:put", "appsecrets:delete", "usersecrets:read", "usersecrets:list", "usersecrets:put", "usersecrets:delete", "opsecrets:read", "opsecrets:write", "settings:read", "settings:write", "designtokens:read", "designtokens:write", "models:read", "models:write", "configs:read", "configs:write", "signinproviders:read", "signinproviders:write", "apps:read", "apps:write", "events:read", "targeting:debug", "visitors:forward", "apikeys:read", "apikeys:write", "organizations:read", "organizations:create", "organizations:delete", "organizations:write", "organizations:reach", "members:read", "members:write", "roles:read", "roles:write", "projects:read", "projects:write", "audit:read"]],
|
|
156
|
+
["projects:create", "none", [], []],
|
|
157
|
+
["projects:delete", "none", [], []],
|
|
158
|
+
["tenants:read", "none", [], []],
|
|
159
|
+
["tenants:write", "none", [], []],
|
|
160
|
+
["tenants:delete", "none", [], []],
|
|
161
|
+
["audit:read", "none", [], []],
|
|
162
|
+
["export:run", "none", [], []],
|
|
163
|
+
["billing:read", "none", [], []],
|
|
164
|
+
["billing:manage", "none", [], []],
|
|
165
|
+
["usage:read", "none", [], []],
|
|
166
|
+
["controlkeys:read", "none", [], []],
|
|
167
|
+
["controlkeys:write", "none", [], []],
|
|
168
|
+
["tenanthooks:read", "none", [], []],
|
|
169
|
+
["tenanthooks:write", "none", [], []],
|
|
170
|
+
["apps:install", "none", [], []],
|
|
171
|
+
["tenant:manage", "none", [], ["project:manage", "projects:create", "projects:delete", "tenants:read", "tenants:write", "tenants:delete", "export:run", "billing:read", "billing:manage", "usage:read", "controlkeys:read", "controlkeys:write", "tenanthooks:read", "tenanthooks:write", "apps:install"]],
|
|
172
|
+
["platform:read", "none", [], []],
|
|
173
|
+
["platform:manage", "none", [], ["tenant:manage", "platform:read", "platform:create_workspace"]],
|
|
174
|
+
["platform:create_workspace", "none", [], []],
|
|
175
|
+
["users:read", "none", ["own", "named", "all"], []],
|
|
176
|
+
["users:write", "none", ["own", "all"], []],
|
|
177
|
+
["users:setup", "none", [], []],
|
|
178
|
+
["users:delete", "none", ["own", "all"], []],
|
|
179
|
+
["users:create", "none", [], []],
|
|
180
|
+
["identities:read", "none", [], []],
|
|
181
|
+
["identities:delete", "none", [], []],
|
|
182
|
+
["usersecrets:read", "none", [], []],
|
|
183
|
+
["usersecrets:list", "none", [], []],
|
|
184
|
+
["usersecrets:put", "none", [], []],
|
|
185
|
+
["usersecrets:delete", "none", [], []],
|
|
186
|
+
["auth:login_with_foir", "none", [], []],
|
|
187
|
+
["signinproviders:read", "none", [], []],
|
|
188
|
+
["signinproviders:write", "none", [], []]
|
|
191
189
|
];
|
|
192
190
|
|
|
193
191
|
// src/auth/grants.ts
|
|
192
|
+
var FIELD_PERMISSIONS = ["records:read", "records:write"];
|
|
193
|
+
var FIELD_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
194
194
|
var index;
|
|
195
195
|
function catalogue() {
|
|
196
196
|
if (!index) {
|
|
@@ -226,8 +226,12 @@ function parseGrant(s) {
|
|
|
226
226
|
let target = "";
|
|
227
227
|
if (rest.startsWith(":")) {
|
|
228
228
|
target = rest.slice(1);
|
|
229
|
-
if (
|
|
229
|
+
if (permission[1] === "none") return null;
|
|
230
230
|
if (target === "" || /[: \t\n*]/.test(target)) return null;
|
|
231
|
+
const dot = target.indexOf(".");
|
|
232
|
+
if (permission[1] === "model" && dot >= 0) {
|
|
233
|
+
if (!FIELD_PERMISSIONS.includes(name) || dot === 0 || !FIELD_KEY.test(target.slice(dot + 1))) return null;
|
|
234
|
+
}
|
|
231
235
|
}
|
|
232
236
|
return { permission, reach, target };
|
|
233
237
|
}
|
|
@@ -1040,10 +1044,7 @@ async function hmacSha256Hex(secret, body) {
|
|
|
1040
1044
|
var KEY_PREFIXES = [
|
|
1041
1045
|
["foir_pub_", "publishable"],
|
|
1042
1046
|
["foir_srv_", "server"],
|
|
1043
|
-
["foir_adm_", "admin"]
|
|
1044
|
-
["pk_", "publishable"],
|
|
1045
|
-
["sk_", "older"],
|
|
1046
|
-
["tc_", "older"]
|
|
1047
|
+
["foir_adm_", "admin"]
|
|
1047
1048
|
];
|
|
1048
1049
|
function foirKeyKind(apiKey) {
|
|
1049
1050
|
if (typeof apiKey !== "string") return void 0;
|
|
@@ -1488,7 +1489,7 @@ function parseResumeFrom(message) {
|
|
|
1488
1489
|
const n = Number(m[1]);
|
|
1489
1490
|
return Number.isSafeInteger(n) ? n : void 0;
|
|
1490
1491
|
}
|
|
1491
|
-
function
|
|
1492
|
+
function assertAdminKey(apiKey) {
|
|
1492
1493
|
const key = apiKey?.trim() ?? "";
|
|
1493
1494
|
if (!key) {
|
|
1494
1495
|
throw new FoirRequestError(
|
|
@@ -1513,7 +1514,7 @@ function assertNoBearer(headers) {
|
|
|
1513
1514
|
for (const name of Object.keys(headers)) {
|
|
1514
1515
|
if (name.toLowerCase() === "authorization") {
|
|
1515
1516
|
throw new FoirRequestError(
|
|
1516
|
-
`[foir] createEventsClient: an Authorization header is not accepted. A user bearer makes the user the resolved authority on api-public, and no user authority can contain ${FOIR_EVENTS_SCOPE}. The
|
|
1517
|
+
`[foir] createEventsClient: an Authorization header is not accepted. A user bearer makes the user the resolved authority on api-public, and no user authority can contain ${FOIR_EVENTS_SCOPE}. The admin key alone is the credential for this surface.`
|
|
1517
1518
|
);
|
|
1518
1519
|
}
|
|
1519
1520
|
}
|
|
@@ -1575,7 +1576,7 @@ async function readErrorMessage(res) {
|
|
|
1575
1576
|
}
|
|
1576
1577
|
}
|
|
1577
1578
|
function createEventsClient(config) {
|
|
1578
|
-
const apiKey =
|
|
1579
|
+
const apiKey = assertAdminKey(config.apiKey);
|
|
1579
1580
|
assertNoBearer(config.headers);
|
|
1580
1581
|
const url = foirApiEndpoint(config.apiUrl, FOIR_EVENTS_PATH);
|
|
1581
1582
|
async function list(params = {}) {
|
|
@@ -31,7 +31,7 @@ export interface FoirEnv {
|
|
|
31
31
|
*
|
|
32
32
|
* Preview is selected at the environment level, not per-request: load a
|
|
33
33
|
* preview env file that sets `FOIR_PREVIEW=true` + the preview environment's
|
|
34
|
-
* own
|
|
34
|
+
* own publishable key holding `drafts:read` as `PLATFORM_PREVIEW_API_KEY`, instead
|
|
35
35
|
* of the default env.
|
|
36
36
|
* The site-wide mode keeps draft semantics consistent — every loader sees
|
|
37
37
|
* the same preview/published view of the world. Intended for non-production
|
|
@@ -6,30 +6,19 @@
|
|
|
6
6
|
* app's pages. An admin key is a machine's own: a sync job, a pipeline, a tool.
|
|
7
7
|
* A key says its kind in its first letters, so this is decided without a
|
|
8
8
|
* request.
|
|
9
|
-
*
|
|
10
|
-
* A key minted before a key had a kind says an older type. A `pk_` key is a
|
|
11
|
-
* publishable key. An `sk_` or a `tc_` key says only that it is not public:
|
|
12
|
-
* the platform holds it as an admin key, and it is reported here as `older`,
|
|
13
|
-
* so that a caller who refuses an admin key by name does not refuse a key
|
|
14
|
-
* whose holder has not yet been able to mint a server key in its place.
|
|
15
9
|
*/
|
|
16
10
|
export type FoirKeyKind = 'publishable' | 'server' | 'admin';
|
|
17
|
-
/** What a key's prefix says of it: its kind, or that it is an older secret. */
|
|
18
|
-
export type FoirKeyPrefixKind = FoirKeyKind | 'older';
|
|
19
11
|
/** Where each credential is for, and which key an app holds. */
|
|
20
12
|
export declare const FOIR_CREDENTIALS_DOC = "https://docs.foir.dev/credentials";
|
|
21
13
|
/**
|
|
22
14
|
* What a key says of itself by its prefix, or `undefined` for a string that
|
|
23
15
|
* is no key Fóir made.
|
|
24
16
|
*/
|
|
25
|
-
export declare function foirKeyKind(apiKey: string | null | undefined):
|
|
17
|
+
export declare function foirKeyKind(apiKey: string | null | undefined): FoirKeyKind | undefined;
|
|
26
18
|
/**
|
|
27
19
|
* What an app's client says when it is handed an admin key, naming the client
|
|
28
20
|
* it was handed to. An admin key is a machine's own, so every client an app
|
|
29
21
|
* builds refuses one before any request, in the same words.
|
|
30
|
-
*
|
|
31
|
-
* Only a key that says it is an admin key by its prefix is refused. A key
|
|
32
|
-
* minted before a key had a kind does not say, and is let through.
|
|
33
22
|
*/
|
|
34
23
|
export declare function adminKeyRefusal(client: string): string;
|
|
35
24
|
/**
|