@flytedesk/app-kit 8.0.0 → 10.0.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 (59) hide show
  1. package/README.md +135 -4
  2. package/dist/auth/errors.d.ts +20 -0
  3. package/dist/auth/errors.js +24 -0
  4. package/dist/auth/errors.js.map +1 -1
  5. package/dist/auth/guards.d.ts +18 -0
  6. package/dist/auth/guards.js +34 -0
  7. package/dist/auth/guards.js.map +1 -1
  8. package/dist/auth/idpFetch.d.ts +26 -0
  9. package/dist/auth/idpFetch.js +38 -0
  10. package/dist/auth/idpFetch.js.map +1 -0
  11. package/dist/auth/index.d.ts +10 -4
  12. package/dist/auth/index.js +8 -2
  13. package/dist/auth/index.js.map +1 -1
  14. package/dist/auth/oidc-client.d.ts +35 -7
  15. package/dist/auth/oidc-client.js +69 -37
  16. package/dist/auth/oidc-client.js.map +1 -1
  17. package/dist/auth/plugin.d.ts +5 -0
  18. package/dist/auth/plugin.js +158 -56
  19. package/dist/auth/plugin.js.map +1 -1
  20. package/dist/auth/readRoute.d.ts +20 -0
  21. package/dist/auth/readRoute.js +20 -0
  22. package/dist/auth/readRoute.js.map +1 -0
  23. package/dist/auth/service/index.d.ts +61 -0
  24. package/dist/auth/service/index.js +145 -0
  25. package/dist/auth/service/index.js.map +1 -0
  26. package/dist/auth/serviceTokenContract.d.ts +33 -0
  27. package/dist/auth/serviceTokenContract.js +40 -0
  28. package/dist/auth/serviceTokenContract.js.map +1 -0
  29. package/dist/auth/shared-types.d.ts +6 -3
  30. package/dist/auth/shared-types.js.map +1 -1
  31. package/dist/auth/testing/fake-idp.d.ts +97 -1
  32. package/dist/auth/testing/fake-idp.js +179 -1
  33. package/dist/auth/testing/fake-idp.js.map +1 -1
  34. package/dist/auth/testing/index.d.ts +1 -1
  35. package/dist/auth/testing/index.js +1 -1
  36. package/dist/auth/testing/index.js.map +1 -1
  37. package/dist/auth/types.d.ts +29 -5
  38. package/dist/bigquery/errors.d.ts +34 -8
  39. package/dist/bigquery/errors.js +180 -22
  40. package/dist/bigquery/errors.js.map +1 -1
  41. package/dist/bigquery/index.d.ts +2 -1
  42. package/dist/bigquery/index.js +1 -1
  43. package/dist/bigquery/index.js.map +1 -1
  44. package/dist/bigquery/jobIdentity.d.ts +39 -0
  45. package/dist/bigquery/jobIdentity.js +83 -0
  46. package/dist/bigquery/jobIdentity.js.map +1 -0
  47. package/dist/bigquery/load.d.ts +11 -14
  48. package/dist/bigquery/load.js +132 -56
  49. package/dist/bigquery/load.js.map +1 -1
  50. package/dist/bigquery/query.d.ts +19 -1
  51. package/dist/bigquery/query.js +143 -50
  52. package/dist/bigquery/query.js.map +1 -1
  53. package/dist/bigquery/retry.d.ts +56 -0
  54. package/dist/bigquery/retry.js +110 -0
  55. package/dist/bigquery/retry.js.map +1 -0
  56. package/dist/bigquery/types.d.ts +40 -5
  57. package/dist/profile/plugin.js +11 -7
  58. package/dist/profile/plugin.js.map +1 -1
  59. package/package.json +5 -1
@@ -0,0 +1,56 @@
1
+ export interface RetryOptions {
2
+ /** Total attempts before giving up, including the first, counted across every
3
+ * step of the call (creating the job, checking it, resubmitting it). A
4
+ * positive integer; default 5. Pass 1 for a call that must never be
5
+ * repeated. */
6
+ attempts?: number;
7
+ /** Delay before the first retry; doubles every subsequent retry. Default 1000ms. */
8
+ initialDelayMs?: number;
9
+ /** Injectable for tests — real code always uses a real timer. */
10
+ sleep?: (ms: number) => Promise<void>;
11
+ /** Injectable clock (ms) for tests — real code always uses `Date.now`. */
12
+ now?: () => number;
13
+ }
14
+ /** One call's retry state: the attempts used so far and the time left. */
15
+ export declare class RetryPolicy {
16
+ private readonly what;
17
+ private readonly attempts;
18
+ private readonly initialDelayMs;
19
+ private readonly sleep;
20
+ private readonly now;
21
+ private readonly startedAt;
22
+ private readonly budgetMs;
23
+ private tried;
24
+ private lastTransient;
25
+ /** `budgetMs` is the TOTAL time the whole call may take, backoffs included. */
26
+ constructor(options: RetryOptions, what: string, budgetMs?: number);
27
+ /** Milliseconds of the budget still unspent, rounded up (the whole budget
28
+ * while the clock has not moved), or `undefined` when the call has no
29
+ * budget. Never negative. */
30
+ remainingMs(): number | undefined;
31
+ /** Starts an attempt: counts it and returns the budget left for it
32
+ * (`undefined` when the call has none). Never starts one with no time left:
33
+ * that gives up with the last transient error, or a `JobTimeoutError` when
34
+ * there was none. */
35
+ begin(): number | undefined;
36
+ /** The budget still unspent for a request inside an attempt, or throws when it
37
+ * is gone, so no request is sent with a zero wait. `undefined` when the call
38
+ * has no budget. */
39
+ timeLeft(): number | undefined;
40
+ private giveUp;
41
+ /**
42
+ * Called after an attempt failed with a transient `err` the caller has
43
+ * decided to retry: waits (doubling backoff, never past the budget) so the
44
+ * caller can `begin()` the next attempt. Throws the classified error, with
45
+ * the attempt count, when no attempt is left. When the budget runs out, the
46
+ * backoff is clamped to what is left and the next `begin()` gives up.
47
+ */
48
+ retryAfter(err: unknown): Promise<void>;
49
+ /**
50
+ * Runs `step` (one whole attempt, handed the budget left), retrying it while
51
+ * it fails with an error `shouldRetry` accepts and attempts and budget
52
+ * remain. Any other error is classified and thrown on the attempt that raised
53
+ * it.
54
+ */
55
+ run<T>(step: (remainingMs: number | undefined) => Promise<T>, shouldRetry: (err: unknown) => boolean): Promise<T>;
56
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The one bounded retry of every BigQuery call this module runs (queries, dry
3
+ * runs and load jobs): exponential backoff, a fixed number of attempts shared
4
+ * by every step of one call, and an optional ONE total time budget for the
5
+ * whole call. What may be retried is the caller's predicate for each step
6
+ * (see `isJobLevelFailure`, `isTransientRequestError` in ./errors.js): a
7
+ * request about an existing job is asked again, a job is resubmitted only when
8
+ * the job itself failed or was never created.
9
+ */
10
+ import { BadQueryError, classifyBigQueryError, JobTimeoutError, } from "./errors.js";
11
+ const DEFAULT_ATTEMPTS = 5;
12
+ const DEFAULT_INITIAL_DELAY_MS = 1_000;
13
+ function defaultSleep(ms) {
14
+ return new Promise((resolve) => setTimeout(resolve, ms));
15
+ }
16
+ /** One call's retry state: the attempts used so far and the time left. */
17
+ export class RetryPolicy {
18
+ what;
19
+ attempts;
20
+ initialDelayMs;
21
+ sleep;
22
+ now;
23
+ startedAt;
24
+ budgetMs;
25
+ tried = 0;
26
+ lastTransient;
27
+ /** `budgetMs` is the TOTAL time the whole call may take, backoffs included. */
28
+ constructor(options, what, budgetMs) {
29
+ this.what = what;
30
+ const attempts = options.attempts ?? DEFAULT_ATTEMPTS;
31
+ if (!Number.isInteger(attempts) || attempts < 1) {
32
+ throw new BadQueryError(`${what}: attempts must be a positive integer (got ${String(attempts)})`);
33
+ }
34
+ this.attempts = attempts;
35
+ this.initialDelayMs = options.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
36
+ this.sleep = options.sleep ?? defaultSleep;
37
+ this.now = options.now ?? Date.now;
38
+ this.startedAt = this.now();
39
+ this.budgetMs = budgetMs;
40
+ }
41
+ /** Milliseconds of the budget still unspent, rounded up (the whole budget
42
+ * while the clock has not moved), or `undefined` when the call has no
43
+ * budget. Never negative. */
44
+ remainingMs() {
45
+ if (this.budgetMs === undefined)
46
+ return undefined;
47
+ const elapsed = Math.max(0, this.now() - this.startedAt);
48
+ return Math.max(0, Math.ceil(this.budgetMs - elapsed));
49
+ }
50
+ /** Starts an attempt: counts it and returns the budget left for it
51
+ * (`undefined` when the call has none). Never starts one with no time left:
52
+ * that gives up with the last transient error, or a `JobTimeoutError` when
53
+ * there was none. */
54
+ begin() {
55
+ this.timeLeft();
56
+ this.tried += 1;
57
+ return this.remainingMs();
58
+ }
59
+ /** The budget still unspent for a request inside an attempt, or throws when it
60
+ * is gone, so no request is sent with a zero wait. `undefined` when the call
61
+ * has no budget. */
62
+ timeLeft() {
63
+ const remaining = this.remainingMs();
64
+ if (remaining !== 0)
65
+ return remaining;
66
+ if (this.lastTransient !== undefined) {
67
+ throw this.giveUp(this.lastTransient, "time budget spent");
68
+ }
69
+ throw new JobTimeoutError(this.budgetMs ?? 0);
70
+ }
71
+ giveUp(err, reason) {
72
+ const classified = classifyBigQueryError(err);
73
+ const Ctor = classified.constructor;
74
+ return new Ctor(`${classified.message} (gave up after ${this.tried} attempt${this.tried === 1 ? "" : "s"}: ${reason})`, classified.cause ?? err);
75
+ }
76
+ /**
77
+ * Called after an attempt failed with a transient `err` the caller has
78
+ * decided to retry: waits (doubling backoff, never past the budget) so the
79
+ * caller can `begin()` the next attempt. Throws the classified error, with
80
+ * the attempt count, when no attempt is left. When the budget runs out, the
81
+ * backoff is clamped to what is left and the next `begin()` gives up.
82
+ */
83
+ async retryAfter(err) {
84
+ this.lastTransient = err;
85
+ if (this.tried >= this.attempts)
86
+ throw this.giveUp(err, "no attempts left");
87
+ const delayMs = Math.min(this.initialDelayMs * 2 ** (this.tried - 1), this.remainingMs() ?? Number.POSITIVE_INFINITY);
88
+ console.warn(`[bigquery/retry] ${this.what}: ${classifyBigQueryError(err).name} on attempt ${this.tried}/${this.attempts}, retrying in ${delayMs}ms`);
89
+ await this.sleep(delayMs);
90
+ }
91
+ /**
92
+ * Runs `step` (one whole attempt, handed the budget left), retrying it while
93
+ * it fails with an error `shouldRetry` accepts and attempts and budget
94
+ * remain. Any other error is classified and thrown on the attempt that raised
95
+ * it.
96
+ */
97
+ async run(step, shouldRetry) {
98
+ for (;;) {
99
+ try {
100
+ return await step(this.begin());
101
+ }
102
+ catch (err) {
103
+ if (!shouldRetry(err))
104
+ throw classifyBigQueryError(err);
105
+ await this.retryAfter(err);
106
+ }
107
+ }
108
+ }
109
+ }
110
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/bigquery/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAC;AAiBrB,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,wBAAwB,GAAG,KAAK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AAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;QAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CACtB,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,EAC3C,IAAI,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,iBAAiB,CAC/C,CAAC;QACF,OAAO,CAAC,IAAI,CACV,oBAAoB,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC,GAAG,CAAC,CAAC,IAAI,eAAe,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,iBAAiB,OAAO,IAAI,CACxI,CAAC;QACF,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CACP,IAAqD,EACrD,WAAsC;QAEtC,SAAS,CAAC;YACR,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;YAClC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;oBAAE,MAAM,qBAAqB,CAAC,GAAG,CAAC,CAAC;gBACxD,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -12,6 +12,7 @@
12
12
  * in media-planner.
13
13
  */
14
14
  import type { Writable } from "node:stream";
15
+ import type { RetryOptions } from "./retry.js";
15
16
  /** One structured error entry, same shape the Google APIs client library
16
17
  * attaches to a rejected job promise's `.errors` array. */
17
18
  export interface BigQueryApiErrorDetail {
@@ -47,6 +48,9 @@ export interface BigQueryRawSchema {
47
48
  fields?: BigQueryRawSchemaField[];
48
49
  }
49
50
  export interface BigQueryJobStatistics {
51
+ load?: {
52
+ outputRows?: string;
53
+ };
50
54
  query?: {
51
55
  totalBytesProcessed?: string | number;
52
56
  totalBytesBilled?: string | number;
@@ -83,12 +87,18 @@ export type BigQueryNextQuery = {
83
87
  pageToken?: string;
84
88
  } | null;
85
89
  export interface BigQueryJobLike {
90
+ /** The location BigQuery created the job in (the real `Job#location`). */
91
+ location?: string;
86
92
  /** `@google-cloud/bigquery`'s real `Job#id` is itself `string | undefined`
87
93
  * (inherited from its generic Operation base) — present in practice once a
88
94
  * job has actually been created, but the SDK's own type never guarantees
89
95
  * it. Callers fall back to `""` rather than assume non-null. */
90
96
  id?: string;
91
97
  getMetadata(): Promise<[BigQueryJobMetadata, unknown]>;
98
+ /** Resolves when the job is done; rejects with the job's error if it failed.
99
+ * The load helpers use it on a handle from `BigQueryLike#job` to wait on an
100
+ * existing load job again. */
101
+ promise?(): Promise<unknown>;
92
102
  /** `@google-cloud/bigquery`'s real `Job#getQueryResults` return type varies
93
103
  * in tuple length by overload (a plain `[rows]` when there is nothing else
94
104
  * to report, up to `[rows, nextQuery, apiResponse]`) — accept any prefix of
@@ -199,7 +209,15 @@ export interface BigQueryLoadOptions {
199
209
  writeDisposition?: "WRITE_TRUNCATE" | "WRITE_APPEND" | "WRITE_EMPTY";
200
210
  createDisposition?: "CREATE_IF_NEEDED" | "CREATE_NEVER";
201
211
  labels?: Record<string, string>;
212
+ /** The id the load job is submitted under, reused by every retry of the call
213
+ * (a random one when omitted). Submitting an id that already exists does not
214
+ * fail: the load helpers wait on that job and report ITS result, loading
215
+ * nothing again. */
202
216
  jobId?: string;
217
+ /** The location of the dataset and the load job. BigQuery jobs are per
218
+ * location, so finding the job again after a failed submission needs it for
219
+ * data outside the US and EU multi-regions. */
220
+ location?: string;
203
221
  }
204
222
  export interface BigQueryInsertOptions {
205
223
  skipInvalidRows: boolean;
@@ -226,6 +244,9 @@ export interface BigQueryDatasetLike {
226
244
  }
227
245
  /** A submitted load job, as `BigQuery#createJob` resolves it. */
228
246
  export interface BigQueryLoadJobLike {
247
+ /** The location BigQuery created the job in. BigQuery jobs are per location,
248
+ * so the load helpers keep it to find the job again. */
249
+ location?: string;
229
250
  /** Resolves when the job is done; rejects with the job's error if it failed. */
230
251
  promise(): Promise<unknown>;
231
252
  getMetadata(): Promise<readonly [{
@@ -243,14 +264,22 @@ export interface BigQueryLike {
243
264
  * missing. Mirrors `@google-cloud/bigquery`'s `BigQuery#createJob`. */
244
265
  createJob?(options: {
245
266
  configuration: Record<string, unknown>;
267
+ /** The id to submit the job under (the SDK honours it). */
268
+ jobId?: string;
269
+ /** The location to create the job in (the SDK honours it). */
270
+ location?: string;
246
271
  }): Promise<readonly [BigQueryLoadJobLike, ...unknown[]]>;
247
272
  createQueryJob(options: BigQueryCreateQueryJobOptions): Promise<[BigQueryJobLike, BigQueryJobMetadata]>;
248
- dataset(id: string): BigQueryDatasetLike;
273
+ dataset(id: string, options?: {
274
+ location?: string;
275
+ }): BigQueryDatasetLike;
249
276
  /** Looks up an already-submitted job by id — used to poll extract-job status
250
277
  * independently of the handle returned at submission time. */
251
- job(id: string): BigQueryJobLike;
278
+ job(id: string, options?: {
279
+ location?: string;
280
+ }): BigQueryJobLike;
252
281
  }
253
- export interface RunQueryOptions {
282
+ export interface RunQueryOptions extends RetryOptions {
254
283
  /** The parameterised SQL. Always use `params`/`types` for user-supplied
255
284
  * values — never string-interpolate them into `sql`. */
256
285
  sql: string;
@@ -268,7 +297,9 @@ export interface RunQueryOptions {
268
297
  * it a token it never issued (AK-26). */
269
298
  pageToken?: string;
270
299
  /** The job that produced `pageToken` — required together with it to fetch
271
- * the next page of that same job instead of starting a new one. */
300
+ * the next page of that same job instead of starting a new one. Without a
301
+ * `pageToken` it is the id the new job is submitted under (a random one when
302
+ * omitted), reused by every retry of the call. */
272
303
  jobId?: string;
273
304
  /** Hard cap BigQuery itself enforces on the real job — a job that would
274
305
  * bill more than this many bytes is refused by BigQuery before running,
@@ -293,10 +324,14 @@ export interface RunQueryOptions {
293
324
  export interface QueryPage<T = Record<string, unknown>> {
294
325
  rows: T[];
295
326
  jobId: string;
327
+ /** The location the job runs in, as BigQuery reports it (else the one
328
+ * requested). Pass it back as `RunQueryOptions.location` with `pageToken` to
329
+ * fetch a later page: BigQuery jobs are per location. `runQueryAllPages` does. */
330
+ location?: string;
296
331
  /** Present when another page is available. */
297
332
  nextPageToken?: string;
298
333
  }
299
- export interface EstimateQueryBytesOptions {
334
+ export interface EstimateQueryBytesOptions extends RetryOptions {
300
335
  sql: string;
301
336
  params?: unknown[] | Record<string, unknown>;
302
337
  /** Declared BigQuery parameter types — see `BigQueryParamTypes`. */
@@ -1,5 +1,5 @@
1
1
  import fp from "fastify-plugin";
2
- import { rejectUnauthenticated } from "../auth/guards.js";
2
+ import { authedPerson, rejectUnlessPerson } from "../auth/guards.js";
3
3
  const DEFAULT_ROUTE_PREFIX = "/profile";
4
4
  const PATCHABLE_FIELDS = ["title", "phone", "timezone", "bio"];
5
5
  function assertRequiredOptions(options) {
@@ -66,26 +66,30 @@ const appKitProfilePlugin = async (fastify, options) => {
66
66
  }
67
67
  const routePrefix = options.routePrefix ?? DEFAULT_ROUTE_PREFIX;
68
68
  const store = options.store;
69
+ // A profile belongs to a signed-in person: a service principal is answered 403
70
+ // person_only on both routes (rejectUnlessPerson).
69
71
  /** GET {routePrefix} — the caller's own profile. Never 404s: a user with no row
70
72
  * yet still gets a 200 with every field null (see ProfileStore.findByUserId). */
71
73
  fastify.get(routePrefix, async (request, reply) => {
72
- if (rejectUnauthenticated(request, reply))
74
+ if (rejectUnlessPerson(request, reply))
73
75
  return;
74
- const row = await store.findByUserId(request.authUser.id);
75
- return toResponseBody(request.authUser.id, row);
76
+ const { id } = authedPerson(request);
77
+ const row = await store.findByUserId(id);
78
+ return toResponseBody(id, row);
76
79
  });
77
80
  /** PATCH {routePrefix} — upserts whatever subset of {title, phone, timezone, bio}
78
81
  * is present in the body, scoped to the caller's own row (request.authUser.id is
79
82
  * the only id this handler ever reads or writes — never a caller-supplied one). */
80
83
  fastify.patch(routePrefix, async (request, reply) => {
81
- if (rejectUnauthenticated(request, reply))
84
+ if (rejectUnlessPerson(request, reply))
82
85
  return;
86
+ const { id } = authedPerson(request);
83
87
  const parsed = parsePatchBody(request.body);
84
88
  if ("error" in parsed) {
85
89
  return reply.code(400).send({ error: parsed.error, code: "invalid_body" });
86
90
  }
87
- const row = await store.upsert(request.authUser.id, parsed);
88
- return toResponseBody(request.authUser.id, row);
91
+ const row = await store.upsert(id, parsed);
92
+ return toResponseBody(id, row);
89
93
  });
90
94
  };
91
95
  export const appKitProfile = fp(appKitProfilePlugin, {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/profile/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAQ1D,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAExC,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,CAE5D,CAAC;AAEF,SAAS,qBAAqB,CAAC,OAA6B;IAC1D,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,IACE,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,KAAK,UAAU;QAChD,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,UAAU,EAC1C,CAAC;QACD,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAAc,EAAE,GAAsB;IAC5D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,E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E;IACnD,IAAI,EAAE,4BAA4B;CACnC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flytedesk/app-kit",
3
- "version": "8.0.0",
3
+ "version": "10.0.0",
4
4
  "description": "Shared platform kit for flytedesk apps: flytedesk-id auth (BFF/OIDC client) and a Postgres-native trace/audit layer.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -47,6 +47,10 @@
47
47
  "types": "./dist/auth/testing/index.d.ts",
48
48
  "import": "./dist/auth/testing/index.js"
49
49
  },
50
+ "./auth/service": {
51
+ "types": "./dist/auth/service/index.d.ts",
52
+ "import": "./dist/auth/service/index.js"
53
+ },
50
54
  "./auth/client": {
51
55
  "types": "./dist/auth/client/index.d.ts",
52
56
  "import": "./dist/auth/client/index.js"