@canva/intents 2.0.0 → 2.0.1-beta.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.
Files changed (44) hide show
  1. package/asset/beta.d.ts +1 -0
  2. package/asset/index.d.ts +1 -1
  3. package/beta.d.ts +1309 -0
  4. package/content/beta.d.ts +1246 -0
  5. package/content/index.d.ts +1 -0
  6. package/data/beta.d.ts +1242 -0
  7. package/data/index.d.ts +1 -1242
  8. package/design/beta.d.ts +43 -0
  9. package/design/index.d.ts +1 -43
  10. package/index.d.ts +1 -1309
  11. package/lib/cjs/sdk/intents/asset/beta.js +4 -0
  12. package/lib/cjs/sdk/intents/asset/index.js +15 -1
  13. package/lib/cjs/sdk/intents/beta.js +20 -0
  14. package/lib/cjs/sdk/intents/content/beta.js +13 -0
  15. package/lib/cjs/sdk/intents/content/index.js +18 -0
  16. package/lib/cjs/sdk/intents/data/beta.js +19 -0
  17. package/lib/cjs/sdk/intents/data/index.js +1 -2
  18. package/lib/cjs/sdk/intents/design/beta.js +19 -0
  19. package/lib/cjs/sdk/intents/design/index.js +1 -2
  20. package/lib/cjs/sdk/intents/fake/create.js +24 -0
  21. package/lib/cjs/sdk/intents/index.js +2 -4
  22. package/lib/cjs/sdk/intents/public.js +3 -3
  23. package/lib/cjs/sdk/intents/test/beta.js +18 -0
  24. package/lib/cjs/sdk/intents/test/index.js +19 -0
  25. package/lib/cjs/sdk/intents/version.js +11 -0
  26. package/lib/cjs/sdk/utils/canva_sdk.js +63 -0
  27. package/lib/esm/sdk/intents/asset/beta.js +1 -0
  28. package/lib/esm/sdk/intents/asset/index.js +1 -1
  29. package/lib/esm/sdk/intents/beta.js +3 -0
  30. package/lib/esm/sdk/intents/content/beta.js +3 -0
  31. package/lib/esm/sdk/intents/content/index.js +1 -0
  32. package/lib/esm/sdk/intents/data/beta.js +2 -0
  33. package/lib/esm/sdk/intents/data/index.js +1 -2
  34. package/lib/esm/sdk/intents/design/beta.js +2 -0
  35. package/lib/esm/sdk/intents/design/index.js +1 -2
  36. package/lib/esm/sdk/intents/fake/create.js +14 -0
  37. package/lib/esm/sdk/intents/index.js +1 -3
  38. package/lib/esm/sdk/intents/test/beta.js +1 -0
  39. package/lib/esm/sdk/intents/test/index.js +9 -0
  40. package/lib/esm/sdk/intents/version.js +1 -0
  41. package/lib/esm/sdk/utils/canva_sdk.js +39 -0
  42. package/package.json +26 -16
  43. package/test/beta.d.ts +11 -0
  44. package/test/index.d.ts +1 -0
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -1,4 +1,18 @@
1
- "use strict"
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ _export_star(require("./beta"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -0,0 +1,20 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _version = require("./version");
6
+ _export_star(require("./public"), exports);
7
+ function _export_star(from, to) {
8
+ Object.keys(from).forEach(function(k) {
9
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
10
+ Object.defineProperty(to, k, {
11
+ enumerable: true,
12
+ get: function() {
13
+ return from[k];
14
+ }
15
+ });
16
+ }
17
+ });
18
+ return from;
19
+ }
20
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents', _version.LATEST_VERSION, 'beta');
@@ -0,0 +1,13 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "prepareContentPublisher", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return prepareContentPublisher;
9
+ }
10
+ });
11
+ const { canva_sdk } = window;
12
+ const prepareContentPublisher = canva_sdk.intents.v1.content.prepareContentPublisher;
13
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/content', '2.0.1', 'beta');
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./beta"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -0,0 +1,19 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./public"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
19
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/data', '2.0.1', 'beta');
@@ -16,5 +16,4 @@ function _export_star(from, to) {
16
16
  });
17
17
  return from;
18
18
  }
19
- var _window___canva___sdkRegistration, _window___canva__;
20
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('intents/data', '2.0.0', 'ga');
19
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/data', '2.0.0', 'ga');
@@ -0,0 +1,19 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./public"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
19
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/design', '2.0.1', 'beta');
@@ -16,5 +16,4 @@ function _export_star(from, to) {
16
16
  });
17
17
  return from;
18
18
  }
19
- var _window___canva___sdkRegistration, _window___canva__;
20
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('intents/design', '2.0.0', 'ga');
19
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/design', '2.0.0', 'ga');
@@ -0,0 +1,24 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createFakeIntentsClients", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createFakeIntentsClients;
9
+ }
10
+ });
11
+ function createFakeIntentsClients() {
12
+ return {
13
+ intents: {
14
+ v1: {
15
+ design: {
16
+ prepareDesignEditor: ()=>{}
17
+ },
18
+ data: {
19
+ prepareDataConnector: ()=>{}
20
+ }
21
+ }
22
+ }
23
+ };
24
+ }
@@ -1,8 +1,8 @@
1
- "use strict"
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- _export_star(require("./public"), exports);
5
+ _export_star(require("./beta"), exports);
6
6
  function _export_star(from, to) {
7
7
  Object.keys(from).forEach(function(k) {
8
8
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -16,5 +16,3 @@ function _export_star(from, to) {
16
16
  });
17
17
  return from;
18
18
  }
19
- var _window___canva___sdkRegistration, _window___canva__;
20
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('intents', '2.0.0', 'ga');
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  function _export(target, all) {
6
6
  for(var name in all)Object.defineProperty(target, name, {
7
7
  enumerable: true,
8
- get: all[name]
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- data: function() {
12
+ get data () {
13
13
  return _index;
14
14
  },
15
- design: function() {
15
+ get design () {
16
16
  return _index1;
17
17
  }
18
18
  });
@@ -0,0 +1,18 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./index"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -0,0 +1,19 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "initTestEnvironment", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return initTestEnvironment;
9
+ }
10
+ });
11
+ const _create = require('../fake/create');
12
+ const _canva_sdk = require('../../utils/canva_sdk');
13
+ function initTestEnvironment() {
14
+ (0, _canva_sdk.assertIsTestCanvaSdk)();
15
+ const fakeClients = (0, _create.createFakeIntentsClients)();
16
+ (0, _canva_sdk.injectFakeAPIClients)({
17
+ intents: fakeClients.intents
18
+ });
19
+ }
@@ -0,0 +1,11 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "LATEST_VERSION", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return LATEST_VERSION;
9
+ }
10
+ });
11
+ const LATEST_VERSION = '2.0.0';
@@ -0,0 +1,63 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get assertIsTestCanvaSdk () {
13
+ return assertIsTestCanvaSdk;
14
+ },
15
+ get bindMethodsToClients () {
16
+ return bindMethodsToClients;
17
+ },
18
+ get getCanvaSdk () {
19
+ return getCanvaSdk;
20
+ },
21
+ get injectFakeAPIClients () {
22
+ return injectFakeAPIClients;
23
+ }
24
+ });
25
+ function getCanvaSdk() {
26
+ return window.canva_sdk;
27
+ }
28
+ function assertIsTestCanvaSdk() {
29
+ if (window.__canva__?.uiKit) {
30
+ const CanvaError = getCanvaSdk()?.error?.v2.CanvaError;
31
+ throw new CanvaError({
32
+ code: 'failed_precondition',
33
+ message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
34
+ });
35
+ }
36
+ }
37
+ function injectFakeAPIClients(clients) {
38
+ bindMethodsToClients(clients);
39
+ window.canva_sdk = {
40
+ ...getCanvaSdk(),
41
+ ...clients
42
+ };
43
+ }
44
+ function bindMethodsToClients(objectToBind) {
45
+ if (typeof objectToBind !== 'object' || objectToBind == null)
46
+ return;
47
+ const classMethods = new Set();
48
+ let currentPrototype = Object.getPrototypeOf(objectToBind);
49
+ while(currentPrototype && currentPrototype !== Object.prototype){
50
+ Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
51
+ currentPrototype = Object.getPrototypeOf(currentPrototype);
52
+ }
53
+ classMethods.delete('constructor');
54
+ for (const method of classMethods) {
55
+ const originalFn = objectToBind[method];
56
+ if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
57
+ value: (...args)=>{
58
+ return originalFn.call(objectToBind, ...args);
59
+ }
60
+ });
61
+ }
62
+ Object.values(objectToBind).forEach(bindMethodsToClients);
63
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -1 +1 @@
1
- export {};
1
+ export * from './beta';
@@ -0,0 +1,3 @@
1
+ import { LATEST_VERSION } from './version';
2
+ export * from './public';
3
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents', LATEST_VERSION, 'beta');
@@ -0,0 +1,3 @@
1
+ const { canva_sdk } = window;
2
+ export const prepareContentPublisher = canva_sdk.intents.v1.content.prepareContentPublisher;
3
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/content', '2.0.1', 'beta');
@@ -0,0 +1 @@
1
+ export * from './beta';
@@ -0,0 +1,2 @@
1
+ export * from './public';
2
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/data', '2.0.1', 'beta');
@@ -1,3 +1,2 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
2
1
  export * from './public';
3
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('intents/data', '2.0.0', 'ga');
2
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/data', '2.0.0', 'ga');
@@ -0,0 +1,2 @@
1
+ export * from './public';
2
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/design', '2.0.1', 'beta');
@@ -1,3 +1,2 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
2
1
  export * from './public';
3
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('intents/design', '2.0.0', 'ga');
2
+ window.__canva__?.sdkRegistration?.registerPackageVersion('intents/design', '2.0.0', 'ga');
@@ -0,0 +1,14 @@
1
+ export function createFakeIntentsClients() {
2
+ return {
3
+ intents: {
4
+ v1: {
5
+ design: {
6
+ prepareDesignEditor: ()=>{}
7
+ },
8
+ data: {
9
+ prepareDataConnector: ()=>{}
10
+ }
11
+ }
12
+ }
13
+ };
14
+ }
@@ -1,3 +1 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
2
- export * from './public';
3
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('intents', '2.0.0', 'ga');
1
+ export * from './beta';
@@ -0,0 +1 @@
1
+ export * from './index';
@@ -0,0 +1,9 @@
1
+ import { createFakeIntentsClients } from '../fake/create';
2
+ import { assertIsTestCanvaSdk, injectFakeAPIClients } from '../../utils/canva_sdk';
3
+ export function initTestEnvironment() {
4
+ assertIsTestCanvaSdk();
5
+ const fakeClients = createFakeIntentsClients();
6
+ injectFakeAPIClients({
7
+ intents: fakeClients.intents
8
+ });
9
+ }
@@ -0,0 +1 @@
1
+ export const LATEST_VERSION = '2.0.0';
@@ -0,0 +1,39 @@
1
+ export function getCanvaSdk() {
2
+ return window.canva_sdk;
3
+ }
4
+ export function assertIsTestCanvaSdk() {
5
+ if (window.__canva__?.uiKit) {
6
+ const CanvaError = getCanvaSdk()?.error?.v2.CanvaError;
7
+ throw new CanvaError({
8
+ code: 'failed_precondition',
9
+ message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
10
+ });
11
+ }
12
+ }
13
+ export function injectFakeAPIClients(clients) {
14
+ bindMethodsToClients(clients);
15
+ window.canva_sdk = {
16
+ ...getCanvaSdk(),
17
+ ...clients
18
+ };
19
+ }
20
+ export function bindMethodsToClients(objectToBind) {
21
+ if (typeof objectToBind !== 'object' || objectToBind == null)
22
+ return;
23
+ const classMethods = new Set();
24
+ let currentPrototype = Object.getPrototypeOf(objectToBind);
25
+ while(currentPrototype && currentPrototype !== Object.prototype){
26
+ Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
27
+ currentPrototype = Object.getPrototypeOf(currentPrototype);
28
+ }
29
+ classMethods.delete('constructor');
30
+ for (const method of classMethods) {
31
+ const originalFn = objectToBind[method];
32
+ if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
33
+ value: (...args)=>{
34
+ return originalFn.call(objectToBind, ...args);
35
+ }
36
+ });
37
+ }
38
+ Object.values(objectToBind).forEach(bindMethodsToClients);
39
+ }
package/package.json CHANGED
@@ -1,35 +1,45 @@
1
1
  {
2
2
  "name": "@canva/intents",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-beta.1",
4
4
  "description": "The Canva Apps SDK Intents library",
5
5
  "author": "Canva Pty Ltd.",
6
6
  "license": "SEE LICENSE IN LICENSE.md FILE",
7
7
  "peerDependencies": {
8
8
  "@canva/error": "^2.0.0"
9
9
  },
10
- "main": "./lib/cjs/sdk/intents/index.js",
11
- "module": "./lib/esm/sdk/intents/index.js",
10
+ "main": "./lib/cjs/sdk/intents/beta.js",
11
+ "module": "./lib/esm/sdk/intents/beta.js",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./index.d.ts",
15
- "require": "./lib/cjs/sdk/intents/index.js",
16
- "import": "./lib/esm/sdk/intents/index.js"
14
+ "types": "./beta.d.ts",
15
+ "require": "./lib/cjs/sdk/intents/beta.js",
16
+ "import": "./lib/esm/sdk/intents/beta.js"
17
+ },
18
+ "./test": {
19
+ "types": "./test/beta.d.ts",
20
+ "require": "./lib/cjs/sdk/intents/test/beta.js",
21
+ "import": "./lib/esm/sdk/intents/test/beta.js"
17
22
  },
18
23
  "./data": {
19
- "types": "./data/index.d.ts",
20
- "require": "./lib/cjs/sdk/intents/data/index.js",
21
- "import": "./lib/esm/sdk/intents/data/index.js"
24
+ "types": "./data/beta.d.ts",
25
+ "require": "./lib/cjs/sdk/intents/data/beta.js",
26
+ "import": "./lib/esm/sdk/intents/data/beta.js"
22
27
  },
23
28
  "./design": {
24
- "types": "./design/index.d.ts",
25
- "require": "./lib/cjs/sdk/intents/design/index.js",
26
- "import": "./lib/esm/sdk/intents/design/index.js"
29
+ "types": "./design/beta.d.ts",
30
+ "require": "./lib/cjs/sdk/intents/design/beta.js",
31
+ "import": "./lib/esm/sdk/intents/design/beta.js"
27
32
  },
28
33
  "./asset": {
29
- "types": "./asset/index.d.ts",
30
- "require": "./lib/cjs/sdk/intents/asset/index.js",
31
- "import": "./lib/esm/sdk/intents/asset/index.js"
34
+ "types": "./asset/beta.d.ts",
35
+ "require": "./lib/cjs/sdk/intents/asset/beta.js",
36
+ "import": "./lib/esm/sdk/intents/asset/beta.js"
37
+ },
38
+ "./content": {
39
+ "types": "./content/beta.d.ts",
40
+ "require": "./lib/cjs/sdk/intents/content/beta.js",
41
+ "import": "./lib/esm/sdk/intents/content/beta.js"
32
42
  }
33
43
  },
34
- "typings": "./index.d.ts"
44
+ "typings": "./beta.d.ts"
35
45
  }
package/test/beta.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @public
3
+ * Initializes a test environment for the `@canva/intents` package, enabling unit tests to mock Canva's APIs.
4
+ * @remarks
5
+ * This method should only be called once in a test environment, such as in a Jest setup file.
6
+ * @see
7
+ * https://www.canva.dev/docs/apps/testing/
8
+ */
9
+ export declare function initTestEnvironment(): void;
10
+
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./beta";