@canva/platform 0.0.1-rc.1 → 1.0.1

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/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @canva/platform
2
+
3
+ A package for Canva's Apps SDK that provides utility methods.
4
+
5
+ ![](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
6
+
7
+ ## Table of contents
8
+
9
+ - [Introduction](#introduction)
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [API reference](#api-reference)
13
+ - [Related packages](#related-packages)
14
+ - [Contributing](#contributing)
15
+ - [License](#license)
16
+
17
+ ## Introduction
18
+
19
+ `@canva/platform` is an npm package for Canva's [Apps SDK](https://www.canva.dev/docs/apps). It provides utility methods that are useful for a broad range of apps. For example, the `requestOpenExternalUrl` method opens an external web page.
20
+
21
+ **Note:** To get up and running with the Apps SDK, check out [the quick start guide](https://www.canva.dev/docs/apps/quick-start).
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @canva/platform
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ 1. Import a method or namespace from the `@canva/platform` package:
32
+
33
+ ```ts
34
+ import { getPlatformInfo } from '@canva/platform';
35
+ ```
36
+
37
+ 2. Call a method, passing in the required arguments (if any):
38
+
39
+ ```ts
40
+ getPlatformInfo();
41
+ ```
42
+
43
+ ## API reference
44
+
45
+ - [`getPlatformInfo`](https://www.canva.dev/docs/apps/api/platform-get-platform-info)
46
+ - [`requestOpenExternalUrl`](https://www.canva.dev/docs/apps/api/platform-request-open-external-url)
47
+
48
+ ## Related packages
49
+
50
+ The Apps SDK is made up of the following packages:
51
+
52
+ - [`@canva/app-ui-kit`](https://www.npmjs.com/package/@canva/app-ui-kit) - React-based component library for creating apps that mimic the look and feel of Canva.
53
+ - [`@canva/asset`](https://www.npmjs.com/package/@canva/asset) - Provides methods for working with assets, such as image and video files.
54
+ - [`@canva/design`](https://www.npmjs.com/package/@canva/design) - Provides methods for interacting with the user's design, such as creating elements.
55
+ - [`@canva/error`](https://www.npmjs.com/package/@canva/error) - Provides a `CanvaError` class for handling errors.
56
+ - [`@canva/platform`](https://www.npmjs.com/package/@canva/platform) - Provides utility methods, such as a method for opening external links.
57
+ - [`@canva/user`](https://www.npmjs.com/package/@canva/user) - Provides methods for accessing user data and authenticating users.
58
+
59
+ ## Contributing
60
+
61
+ We're actively developing this package but are not currently accepting third-party contributions. If you'd like to request any changes or additions to the package, submit a feature request via the [Canva Developers Community](https://community.canva.dev/).
62
+
63
+ ## License
64
+
65
+ See the `LICENSE.md` file.
package/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @public
3
+ * Returns information about the platform on which the app is running.
4
+ */
5
+ export declare function getPlatformInfo(): PlatformInfo;
6
+
1
7
  /**
2
8
  * @public
3
9
  * The result of opening an external URL when a user chooses to not navigate away from Canva.
@@ -39,6 +45,33 @@ export declare type OpenExternalUrlResponse =
39
45
  | OpenExternalUrlCompleted
40
46
  | OpenExternalUrlAborted;
41
47
 
48
+ /**
49
+ * @public
50
+ * Information about the platform on which the app is running.
51
+ */
52
+ export declare type PlatformInfo = {
53
+ /**
54
+ * If `true`, the app is allowed to directly link to payment and upgrade flows.
55
+ *
56
+ * @remarks
57
+ * This property is always `true` when the app is running in a web browser, but may otherwise be `false` in
58
+ * order to comply with the policies of the platforms on which Canva is available. For example, some platforms
59
+ * only allow payment-related actions that use their own payment mechanisms and apps are therefore not allowed
60
+ * to render payment-related call-to-actions while running on those platforms.
61
+ *
62
+ * @example
63
+ * const info = getPlatformInfo();
64
+ *
65
+ * if (info.canAcceptPayments) {
66
+ * // Display payment links and upgrade flows
67
+ * } else {
68
+ * // Hide payment links and upgrade flows
69
+ * // Optionally show an appropriate message
70
+ * }
71
+ */
72
+ canAcceptPayments: boolean;
73
+ };
74
+
42
75
  /**
43
76
  * @public
44
77
  * Opens an external URL.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requestOpenExternalUrl = void 0;
3
+ exports.getPlatformInfo = exports.requestOpenExternalUrl = void 0;
4
4
  const { canva } = window;
5
5
  /**
6
6
  * @public
@@ -15,3 +15,11 @@ function requestOpenExternalUrl(request) {
15
15
  return canva.platform.requestOpenExternalUrl(request);
16
16
  }
17
17
  exports.requestOpenExternalUrl = requestOpenExternalUrl;
18
+ /**
19
+ * @public
20
+ * Returns information about the platform on which the app is running.
21
+ */
22
+ function getPlatformInfo() {
23
+ return canva.platform.getPlatformInfo();
24
+ }
25
+ exports.getPlatformInfo = getPlatformInfo;
@@ -11,3 +11,10 @@ const { canva } = window;
11
11
  export function requestOpenExternalUrl(request) {
12
12
  return canva.platform.requestOpenExternalUrl(request);
13
13
  }
14
+ /**
15
+ * @public
16
+ * Returns information about the platform on which the app is running.
17
+ */
18
+ export function getPlatformInfo() {
19
+ return canva.platform.getPlatformInfo();
20
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@canva/platform",
3
- "version": "0.0.1-rc.1",
4
- "description": "The Canva Apps SDK App Platform Library",
3
+ "version": "1.0.1",
4
+ "description": "The Canva Apps SDK app platform library",
5
5
  "author": "Canva Pty Ltd.",
6
6
  "license": "SEE LICENSE IN LICENSE.md FILE",
7
7
  "peerDependencies": {
8
- "@canva/error": "^0.0.1-rc.1"
8
+ "@canva/error": "^1.0.0"
9
9
  },
10
10
  "main": "lib/cjs/sdk/platform/index.js",
11
11
  "module": "lib/esm/sdk/platform/index.js",