@archilogic/extension-sdk 0.18.0 → 0.19.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @archilogic/extension-sdk
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9264f69: add `hostApi.getApiAccess()`, so an extension whose temporary access token is about to expire can
8
+ ask the host for a fresh one instead of holding the one it got at connect. The credentials are now
9
+ a named `ApiAccess` type rather than an inline shape repeated on both sides.
10
+
3
11
  ## 0.18.0
4
12
 
5
13
  ### Minor Changes
package/dist/actions.d.ts CHANGED
@@ -131,6 +131,21 @@ declare type AnnotationUpdateValue = Partial<LayoutAnnotationJson> & {
131
131
  parameters?: Partial<LayoutAnnotationJson['parameters']>;
132
132
  };
133
133
 
134
+ /**
135
+ * Space API credentials the host issues to an extension that declares `apiAccess` under
136
+ * `parameters` in its manifest. Delivered once in the `onConnect` parameters and, from then on,
137
+ * on demand via `hostApi.getApiAccess()` — the token is short-lived (an hour today), so an
138
+ * extension that outlives it has to ask for a fresh one rather than hold the first forever.
139
+ */
140
+ declare type ApiAccess = {
141
+ /** Value for the `authorization` header. */
142
+ temporaryAccessToken: string;
143
+ /** Unix timestamp in **seconds** at which the token stops working. */
144
+ expiresAt: number;
145
+ /** Base URL of the Space API, e.g. `https://api.archilogic.com`. */
146
+ apiUrl: string;
147
+ };
148
+
134
149
  declare interface Arc {
135
150
  center: Vector2;
136
151
  radius: number;
@@ -1404,6 +1419,25 @@ declare type HostApi = {
1404
1419
  }) => Promise<NodeResult[]>;
1405
1420
  getSpaceGraphJson: () => Promise<SpaceGraphJson>;
1406
1421
  getSharedViewStyles: () => Promise<SharedViewStyle[]>;
1422
+ /**
1423
+ * Space API credentials for this extension, freshly minted by the host. Only extensions that
1424
+ * declare `apiAccess` under `parameters` in their manifest get them — anything else resolves
1425
+ * `null`, as does a host that cannot issue a token.
1426
+ *
1427
+ * The host also delivers credentials once in the `onConnect` parameters, so an extension that
1428
+ * finishes its work inside the token's lifetime never needs this. Call it when the token you
1429
+ * hold is close to `expiresAt` — the host returns a new one with a full lifetime rather than
1430
+ * extending the old.
1431
+ *
1432
+ * @example
1433
+ * ```ts
1434
+ * // ~1 minute of headroom, expiresAt is in seconds
1435
+ * if (apiAccess.expiresAt - Date.now() / 1000 < 60) {
1436
+ * apiAccess = (await hostApi.getApiAccess()) ?? apiAccess
1437
+ * }
1438
+ * ```
1439
+ */
1440
+ getApiAccess: () => Promise<ApiAccess | null>;
1407
1441
  exportPdf: (args?: ExportPdfOptions) => Promise<void | ExportPdfResult>;
1408
1442
  exportSvg: (args?: ExportSvgOptions) => Promise<void | ExportSvgResult>;
1409
1443
  getPath: (args: {
package/dist/index.d.ts CHANGED
@@ -59,6 +59,21 @@ declare type AnnotationUpdateValue = Partial<LayoutAnnotationJson> & {
59
59
  parameters?: Partial<LayoutAnnotationJson['parameters']>;
60
60
  };
61
61
 
62
+ /**
63
+ * Space API credentials the host issues to an extension that declares `apiAccess` under
64
+ * `parameters` in its manifest. Delivered once in the `onConnect` parameters and, from then on,
65
+ * on demand via `hostApi.getApiAccess()` — the token is short-lived (an hour today), so an
66
+ * extension that outlives it has to ask for a fresh one rather than hold the first forever.
67
+ */
68
+ export declare type ApiAccess = {
69
+ /** Value for the `authorization` header. */
70
+ temporaryAccessToken: string;
71
+ /** Unix timestamp in **seconds** at which the token stops working. */
72
+ expiresAt: number;
73
+ /** Base URL of the Space API, e.g. `https://api.archilogic.com`. */
74
+ apiUrl: string;
75
+ };
76
+
62
77
  declare interface Arc {
63
78
  center: Vector2;
64
79
  radius: number;
@@ -1311,6 +1326,25 @@ export declare type HostApi = {
1311
1326
  }) => Promise<NodeResult[]>;
1312
1327
  getSpaceGraphJson: () => Promise<SpaceGraphJson>;
1313
1328
  getSharedViewStyles: () => Promise<SharedViewStyle[]>;
1329
+ /**
1330
+ * Space API credentials for this extension, freshly minted by the host. Only extensions that
1331
+ * declare `apiAccess` under `parameters` in their manifest get them — anything else resolves
1332
+ * `null`, as does a host that cannot issue a token.
1333
+ *
1334
+ * The host also delivers credentials once in the `onConnect` parameters, so an extension that
1335
+ * finishes its work inside the token's lifetime never needs this. Call it when the token you
1336
+ * hold is close to `expiresAt` — the host returns a new one with a full lifetime rather than
1337
+ * extending the old.
1338
+ *
1339
+ * @example
1340
+ * ```ts
1341
+ * // ~1 minute of headroom, expiresAt is in seconds
1342
+ * if (apiAccess.expiresAt - Date.now() / 1000 < 60) {
1343
+ * apiAccess = (await hostApi.getApiAccess()) ?? apiAccess
1344
+ * }
1345
+ * ```
1346
+ */
1347
+ getApiAccess: () => Promise<ApiAccess | null>;
1314
1348
  exportPdf: (args?: ExportPdfOptions) => Promise<void | ExportPdfResult>;
1315
1349
  exportSvg: (args?: ExportSvgOptions) => Promise<void | ExportSvgResult>;
1316
1350
  getPath: (args: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@archilogic/extension-sdk",
3
3
  "description": "",
4
- "version": "0.18.0",
4
+ "version": "0.19.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },