@foir/sdk 0.11.0 → 0.12.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +131 -2
  2. package/dist/app/client.d.ts +371 -0
  3. package/dist/app/contract/index.d.ts +23 -0
  4. package/dist/app/contract/proto/apps/v1/apps_pb.d.ts +1465 -0
  5. package/dist/app/contract/proto/apps/v1/discovery_pb.d.ts +678 -0
  6. package/dist/app/dispatch.d.ts +64 -0
  7. package/dist/app/errors.d.ts +50 -0
  8. package/dist/app/index.d.ts +40 -0
  9. package/dist/app/manifest.d.ts +56 -0
  10. package/dist/app/naming.d.ts +31 -0
  11. package/dist/app/record-key.d.ts +17 -0
  12. package/dist/app/ticket.d.ts +37 -0
  13. package/dist/app/vocabulary.generated.d.ts +20 -0
  14. package/dist/app-contract.js +124 -0
  15. package/dist/app.js +998 -0
  16. package/dist/auth/auth.d.ts +24 -6
  17. package/dist/auth/index.d.ts +2 -1
  18. package/dist/auth.js +139 -23
  19. package/dist/client.js +36 -2
  20. package/dist/data/index.d.ts +2 -2
  21. package/dist/data/transport.d.ts +34 -2
  22. package/dist/data.js +77 -2
  23. package/dist/graphql/client.d.ts +1 -1
  24. package/dist/graphql/foir-request.d.ts +1 -1
  25. package/dist/next.js +70 -2
  26. package/dist/placement/index.d.ts +129 -0
  27. package/dist/placement.js +144 -0
  28. package/dist/push.js +121 -13
  29. package/dist/react.js +70 -2
  30. package/dist/server/callback-client.d.ts +30 -9
  31. package/dist/server/continue-run.d.ts +56 -0
  32. package/dist/server/index.d.ts +5 -3
  33. package/dist/server/operation-types.d.ts +28 -7
  34. package/dist/server/require-scoped-token.d.ts +52 -7
  35. package/dist/server/verify-scoped-token.d.ts +109 -3
  36. package/dist/server.js +415 -127
  37. package/dist/transport/foir-http.d.ts +48 -0
  38. package/package.json +24 -6
@@ -211,6 +211,12 @@ export interface FoirRequestOptions {
211
211
  * (e.g. `myProfile`). Used by `@foir/sdk/auth`'s post-login profile fetch.
212
212
  */
213
213
  bearerToken?: string;
214
+ /**
215
+ * Refuse an answer served without the bearer this request sent: throw
216
+ * {@link FoirAuthDowngradedError} instead of returning the anonymous data.
217
+ * `authedRequest` sets it, so it can refresh and ask again.
218
+ */
219
+ rejectDowngrade?: boolean;
214
220
  /**
215
221
  * The organization this request acts in, sent as `X-Org-Id`. For a
216
222
  * project-scoped key: the server resolves it to an active organization of
@@ -283,6 +289,11 @@ export interface FoirKeyHeaderInput {
283
289
  * Set from `FoirClientConfig.orgUrl` / `FoirRequestOptions.orgUrl`.
284
290
  */
285
291
  orgUrl?: string;
292
+ /**
293
+ * The address of the visitor a server rendering pages is calling for
294
+ * (`X-Foir-Visitor-IP`). Set from `FoirClientConfig.visitor`.
295
+ */
296
+ visitorAddress?: string;
286
297
  dispatchToken?: never;
287
298
  dispatchContext?: never;
288
299
  /** Caller-supplied extras, applied last so a caller can override. */
@@ -329,6 +340,19 @@ export declare function refuseCredentialHeaders(extra: Readonly<Record<string, s
329
340
  * optional customer bearer, organization and channel), or an operation's
330
341
  * dispatch token. A dispatch request never writes `x-api-key`.
331
342
  */
343
+ /** The header a server names the visitor it calls for in. */
344
+ export declare const FOIR_VISITOR_IP_HEADER = "X-Foir-Visitor-IP";
345
+ /**
346
+ * The address of the visitor a server rendering pages is calling for, or a
347
+ * function that resolves it for each request.
348
+ *
349
+ * The SDK does not read it off a request, because which request header holds
350
+ * the visitor's real address, and whether a visitor can forge it, depends on
351
+ * what sits in front of your server. Your host says which one its edge sets and
352
+ * strips; that value, and only that, belongs here. A function that yields
353
+ * nothing sends nothing, and the API counts the request as your server's own.
354
+ */
355
+ export type FoirVisitorSource = string | (() => string | null | undefined | Promise<string | null | undefined>);
332
356
  export declare function buildFoirHeaders(input: FoirHeaderInput): Record<string, string>;
333
357
  /**
334
358
  * Build a `/v1/...` URL from whatever the caller put in `apiUrl`.
@@ -371,6 +395,29 @@ export interface FoirAuthDowngrade {
371
395
  /** The authority the request actually ran under. */
372
396
  servedAs: string;
373
397
  }
398
+ /**
399
+ * A request that sent a customer token was served without it.
400
+ *
401
+ * Thrown only to a caller that asked (`rejectDowngrade`): one that sent the
402
+ * token because it wants the signed-in answer, and would otherwise be handed the
403
+ * anonymous one as though nothing had happened. `downgrade.reason` says whether
404
+ * refreshing could help: `expired` can be refreshed, `invalid` and
405
+ * `wrong_project` cannot.
406
+ */
407
+ export declare class FoirAuthDowngradedError extends FoirRequestError {
408
+ readonly downgrade: FoirAuthDowngrade;
409
+ constructor(downgrade: FoirAuthDowngrade);
410
+ }
411
+ /**
412
+ * The customer's session is over: its token was rejected and could not be
413
+ * refreshed. It is what a signed-in request gets in place of the anonymous
414
+ * answer. Send the customer to sign in again.
415
+ */
416
+ export declare class FoirSessionExpiredError extends FoirRequestError {
417
+ constructor(options?: {
418
+ cause?: unknown;
419
+ });
420
+ }
374
421
  export interface FoirResponseEnvelope<T> {
375
422
  data?: T;
376
423
  errors?: Array<FoirGraphQLErrorItem>;
@@ -384,4 +431,5 @@ export interface FoirResponseEnvelope<T> {
384
431
  }
385
432
  export declare function readFoirEnvelope<T>(json: FoirResponseEnvelope<T>, options?: {
386
433
  strict?: boolean;
434
+ rejectDowngrade?: boolean;
387
435
  }): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foir/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Official Foir SDK — editor iframe client + server-side platform helpers",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -45,6 +45,18 @@
45
45
  "types": "./dist/auth/index.d.ts",
46
46
  "import": "./dist/auth.js"
47
47
  },
48
+ "./placement": {
49
+ "types": "./dist/placement/index.d.ts",
50
+ "import": "./dist/placement.js"
51
+ },
52
+ "./app": {
53
+ "types": "./dist/app/index.d.ts",
54
+ "import": "./dist/app.js"
55
+ },
56
+ "./app/contract": {
57
+ "types": "./dist/app/contract/index.d.ts",
58
+ "import": "./dist/app-contract.js"
59
+ },
48
60
  "./auth/session": {
49
61
  "types": "./dist/auth/session-client.d.ts",
50
62
  "import": "./dist/auth-session.js"
@@ -107,6 +119,7 @@
107
119
  "@graphql-typed-document-node/core": "3.2.0"
108
120
  },
109
121
  "peerDependencies": {
122
+ "@bufbuild/protobuf": "^2.12.0",
110
123
  "@graphql-codegen/cli": "^5.0.0",
111
124
  "@graphql-codegen/client-preset": "^4.0.0",
112
125
  "blurhash": "^2.0.0",
@@ -117,6 +130,9 @@
117
130
  "yjs": "^13.6.0"
118
131
  },
119
132
  "peerDependenciesMeta": {
133
+ "@bufbuild/protobuf": {
134
+ "optional": true
135
+ },
120
136
  "@graphql-codegen/cli": {
121
137
  "optional": true
122
138
  },
@@ -143,6 +159,7 @@
143
159
  }
144
160
  },
145
161
  "devDependencies": {
162
+ "@bufbuild/protobuf": "^2.0.0",
146
163
  "@graphql-codegen/cli": "^5.0.7",
147
164
  "@testing-library/react": "^16.2.0",
148
165
  "@types/react": "^19.2.0",
@@ -159,18 +176,19 @@
159
176
  "vitest": "^3.2.4",
160
177
  "ws": "^8.18.0",
161
178
  "y-websocket": "^3.0.0",
162
- "yjs": "^13.6.30"
179
+ "yjs": "^13.6.30",
180
+ "@foir/proto-ts": "0.109.0"
163
181
  },
164
182
  "engines": {
165
183
  "node": ">=18.0.0"
166
184
  },
167
185
  "scripts": {
168
- "build": "node scripts/clean-dist.mjs && tsup && tsc -p tsconfig.build.json && node scripts/assert-export-types.mjs && node scripts/assert-public-exports.mjs",
186
+ "build": "node scripts/generate-app-vocabulary.mjs && node scripts/clean-dist.mjs && tsup && tsc -p tsconfig.build.json && node scripts/bundle-app-contract-types.mjs && node scripts/assert-export-types.mjs && node scripts/assert-public-exports.mjs",
169
187
  "snapshot:exports": "node scripts/assert-public-exports.mjs --update",
170
188
  "dev": "node scripts/dev-watch.mjs",
171
- "check-types": "tsc --noEmit",
172
- "test": "vitest run",
173
- "test:watch": "vitest watch",
189
+ "check-types": "node scripts/generate-app-vocabulary.mjs && tsc --noEmit",
190
+ "test": "node scripts/generate-app-vocabulary.mjs && vitest run",
191
+ "test:watch": "node scripts/generate-app-vocabulary.mjs && vitest watch",
174
192
  "release:patch": "pnpm version patch",
175
193
  "release:minor": "pnpm version minor",
176
194
  "release:major": "pnpm version major"