@plattar/plattar-ar-adapter 1.130.2 → 1.132.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.
@@ -6,10 +6,12 @@ export declare class ProductAR extends LauncherAR {
6
6
  private _analytics;
7
7
  private readonly _productID;
8
8
  private readonly _variationID;
9
+ private readonly _variationSKU;
9
10
  private _ar;
10
- constructor(productID?: string | undefined | null, variationID?: string | undefined | null);
11
+ constructor(productID?: string | undefined | null, variationID?: string | undefined | null, variationSKU?: string | undefined | null);
11
12
  get productID(): string;
12
- get variationID(): string;
13
+ get variationID(): string | null;
14
+ get variationSKU(): string | null;
13
15
  private _SetupAnalytics;
14
16
  /**
15
17
  * Initialise the ProductAR instance. This returns a Promise that resolves
@@ -15,7 +15,7 @@ const launcher_ar_1 = require("./launcher-ar");
15
15
  * Performs AR functionality related to Plattar Products and Variation types
16
16
  */
17
17
  class ProductAR extends launcher_ar_1.LauncherAR {
18
- constructor(productID = null, variationID = null) {
18
+ constructor(productID = null, variationID = null, variationSKU = null) {
19
19
  super();
20
20
  // analytics instance
21
21
  this._analytics = null;
@@ -23,7 +23,8 @@ class ProductAR extends launcher_ar_1.LauncherAR {
23
23
  throw new Error("ProductAR.constructor(productID, variationID) - productID must be defined");
24
24
  }
25
25
  this._productID = productID;
26
- this._variationID = variationID ? variationID : "default";
26
+ this._variationSKU = variationSKU;
27
+ this._variationID = variationID ? variationID : (variationSKU ? null : "default");
27
28
  this._ar = null;
28
29
  }
29
30
  get productID() {
@@ -32,6 +33,9 @@ class ProductAR extends launcher_ar_1.LauncherAR {
32
33
  get variationID() {
33
34
  return this._variationID;
34
35
  }
36
+ get variationSKU() {
37
+ return this._variationSKU;
38
+ }
35
39
  _SetupAnalytics(product, variation) {
36
40
  let analytics = null;
37
41
  const scene = product.relationships.find(plattar_api_1.Scene);
@@ -80,14 +84,27 @@ class ProductAR extends launcher_ar_1.LauncherAR {
80
84
  product.include(plattar_api_1.Scene.include(plattar_api_1.Project));
81
85
  product.get().then((product) => {
82
86
  // find the required variation from our product
83
- const variationID = this.variationID ? (this.variationID === "default" ? product.attributes.product_variation_id : this.variationID) : product.attributes.product_variation_id;
84
- if (!variationID) {
85
- return reject(new Error("ProductAR.init() - cannot proceed as variation was not defined correctly"));
87
+ const variationID = this.variationID ? (this.variationID === "default" ? product.attributes.product_variation_id : this.variationID) : null;
88
+ const variationSKU = this.variationSKU;
89
+ if (!variationID && !variationSKU) {
90
+ return reject(new Error("ProductAR.init() - cannot proceed as variation-id or variation-sku was not set correctly"));
91
+ }
92
+ let variation = undefined;
93
+ if (variationID) {
94
+ variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
95
+ }
96
+ // if no variation was found with variationID - try searching variation sku
97
+ if (!variation && variationSKU) {
98
+ const variations = product.relationships.filter(plattar_api_1.ProductVariation);
99
+ if (variations) {
100
+ variation = variations.find((element) => {
101
+ return element.attributes.sku === variationSKU;
102
+ });
103
+ }
86
104
  }
87
- const variation = product.relationships.find(plattar_api_1.ProductVariation, variationID);
88
105
  // make sure our variation is actually available before moving forward
89
106
  if (!variation) {
90
- return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " cannot be found"));
107
+ return reject(new Error("ProductAR.init() - cannot proceed as variation with id " + variationID + " or sku " + variationSKU + " cannot be found"));
91
108
  }
92
109
  // otherwise both the product and variation are available
93
110
  // we need to figure out if we can actually do AR though
@@ -7,7 +7,7 @@ import { LauncherAR } from "./launcher-ar";
7
7
  export declare class SceneProductAR extends ProductAR {
8
8
  private readonly _sceneProductID;
9
9
  private _attachedProductID;
10
- constructor(sceneProductID?: string | undefined | null, variationID?: string | undefined | null);
10
+ constructor(sceneProductID?: string | undefined | null, variationID?: string | undefined | null, variationSKU?: string | undefined | null);
11
11
  get sceneProductID(): string;
12
12
  get productID(): string;
13
13
  init(): Promise<LauncherAR>;
@@ -9,8 +9,8 @@ const util_1 = require("../util/util");
9
9
  * SceneProducts are much more convenient to grab from the Plattar CMS
10
10
  */
11
11
  class SceneProductAR extends product_ar_1.ProductAR {
12
- constructor(sceneProductID = null, variationID = null) {
13
- super(sceneProductID, variationID);
12
+ constructor(sceneProductID = null, variationID = null, variationSKU = null) {
13
+ super(sceneProductID, variationID, variationSKU);
14
14
  // this is evaluated in the init() function
15
15
  this._attachedProductID = null;
16
16
  if (!sceneProductID) {
@@ -30,7 +30,7 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
30
30
  this.removeRenderer();
31
31
  const sceneID = this.getAttribute("scene-id");
32
32
  if (sceneID) {
33
- const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
33
+ const opt = options || this._GetDefaultQROptions();
34
34
  const viewer = document.createElement("plattar-qrcode");
35
35
  // required attributes with defaults for plattar-viewer node
36
36
  const width = this.getAttribute("width") || "500px";
@@ -46,10 +46,15 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
46
46
  if (opt.qrType) {
47
47
  viewer.setAttribute("qr-type", opt.qrType);
48
48
  }
49
+ viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
49
50
  let dst = plattar_api_1.Server.location().base + "renderer/configurator.html?scene_id=" + sceneID;
50
51
  // optional attributes
51
52
  const configState = this.getAttribute("config-state");
52
53
  const showAR = this.getAttribute("show-ar");
54
+ const showUI = this.getAttribute("show-ui");
55
+ if (showUI && showUI === "true") {
56
+ dst = plattar_api_1.Server.location().base + "configurator/dist/index.html?scene_id=" + sceneID;
57
+ }
53
58
  if (configState) {
54
59
  dst += "&config_state=" + configState;
55
60
  }
@@ -87,12 +92,16 @@ class ConfiguratorController extends plattar_controller_1.PlattarController {
87
92
  // optional attributes
88
93
  const configState = this.getAttribute("config-state");
89
94
  const showAR = this.getAttribute("show-ar");
95
+ const showUI = this.getAttribute("show-ui");
90
96
  if (configState) {
91
97
  viewer.setAttribute("config-state", configState);
92
98
  }
93
99
  if (showAR) {
94
100
  viewer.setAttribute("show-ar", showAR);
95
101
  }
102
+ if (showUI) {
103
+ viewer.setAttribute("show-ui", showUI);
104
+ }
96
105
  viewer.onload = () => {
97
106
  return accept(viewer);
98
107
  };
@@ -11,7 +11,7 @@ export declare abstract class PlattarController {
11
11
  /**
12
12
  * Default QR Code rendering options
13
13
  */
14
- static get DEFAULT_QR_OPTIONS(): any;
14
+ protected _GetDefaultQROptions(): any;
15
15
  private readonly _parent;
16
16
  protected _state: ControllerState;
17
17
  protected _element: HTMLElement | null;
@@ -21,10 +21,11 @@ class PlattarController {
21
21
  /**
22
22
  * Default QR Code rendering options
23
23
  */
24
- static get DEFAULT_QR_OPTIONS() {
24
+ _GetDefaultQROptions() {
25
25
  return {
26
- color: "#101721",
27
- qrType: "default",
26
+ color: this.getAttribute("qr-color") || "#101721",
27
+ qrType: this.getAttribute("qr-style") || "default",
28
+ shorten: this.getAttribute("qr-shorten") || false,
28
29
  margin: 0
29
30
  };
30
31
  }
@@ -64,7 +65,7 @@ class PlattarController {
64
65
  return new Promise((accept, reject) => {
65
66
  // remove the old renderer instance if any
66
67
  this.removeRenderer();
67
- const opt = options || PlattarController.DEFAULT_QR_OPTIONS;
68
+ const opt = options || this._GetDefaultQROptions();
68
69
  const viewer = document.createElement("plattar-qrcode");
69
70
  // required attributes with defaults for plattar-viewer node
70
71
  const width = this.getAttribute("width") || "500px";
@@ -80,6 +81,7 @@ class PlattarController {
80
81
  if (opt.qrType) {
81
82
  viewer.setAttribute("qr-type", opt.qrType);
82
83
  }
84
+ viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
83
85
  const qrOptions = btoa(JSON.stringify(opt));
84
86
  let dst = plattar_api_1.Server.location().base + "renderer/launcher.html?qr_options=" + qrOptions;
85
87
  const sceneID = this.getAttribute("scene-id");
@@ -88,6 +90,7 @@ class PlattarController {
88
90
  const productID = this.getAttribute("product-id");
89
91
  const sceneProductID = this.getAttribute("scene-product-id");
90
92
  const variationID = this.getAttribute("variation-id");
93
+ const variationSKU = this.getAttribute("variation-sku");
91
94
  const arMode = this.getAttribute("ar-mode");
92
95
  if (configState) {
93
96
  dst += "&config_state=" + configState;
@@ -104,6 +107,9 @@ class PlattarController {
104
107
  if (variationID) {
105
108
  dst += "&variation_id=" + variationID;
106
109
  }
110
+ if (variationSKU) {
111
+ dst += "&variation_sku=" + variationSKU;
112
+ }
107
113
  if (arMode) {
108
114
  dst += "&ar_mode=" + arMode;
109
115
  }
@@ -37,7 +37,7 @@ class ProductController extends plattar_controller_1.PlattarController {
37
37
  this.removeRenderer();
38
38
  const productID = this.getAttribute("product-id");
39
39
  if (productID) {
40
- const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
40
+ const opt = options || this._GetDefaultQROptions();
41
41
  const viewer = document.createElement("plattar-qrcode");
42
42
  // required attributes with defaults for plattar-viewer node
43
43
  const width = this.getAttribute("width") || "500px";
@@ -53,12 +53,17 @@ class ProductController extends plattar_controller_1.PlattarController {
53
53
  if (opt.qrType) {
54
54
  viewer.setAttribute("qr-type", opt.qrType);
55
55
  }
56
+ viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
56
57
  // optional attributes
57
58
  const variationID = this.getAttribute("variation-id");
59
+ const variationSKU = this.getAttribute("variation-sku");
58
60
  const showAR = this.getAttribute("show-ar");
59
61
  let dst = plattar_api_1.Server.location().base + "renderer/product.html?product_id=" + productID;
60
62
  if (variationID) {
61
- dst += "&variation_id=" + variationID;
63
+ dst += "&variationId=" + variationID;
64
+ }
65
+ if (variationSKU) {
66
+ dst += "&variationSku=" + variationSKU;
62
67
  }
63
68
  if (showAR) {
64
69
  dst += "&show_ar=" + showAR;
@@ -93,10 +98,14 @@ class ProductController extends plattar_controller_1.PlattarController {
93
98
  viewer.setAttribute("product-id", productID);
94
99
  // optional attributes
95
100
  const variationID = this.getAttribute("variation-id");
101
+ const variationSKU = this.getAttribute("variation-sku");
96
102
  const showAR = this.getAttribute("show-ar");
97
103
  if (variationID) {
98
104
  viewer.setAttribute("variation-id", variationID);
99
105
  }
106
+ if (variationSKU) {
107
+ viewer.setAttribute("variation-sku", variationSKU);
108
+ }
100
109
  if (showAR) {
101
110
  viewer.setAttribute("show-ar", showAR);
102
111
  }
@@ -119,7 +128,8 @@ class ProductController extends plattar_controller_1.PlattarController {
119
128
  const productID = this.getAttribute("product-id");
120
129
  if (productID) {
121
130
  const variationID = this.getAttribute("variation-id");
122
- const product = new product_ar_1.ProductAR(productID, variationID);
131
+ const variationSKU = this.getAttribute("variation-sku");
132
+ const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
123
133
  return product.init().then(accept).catch(reject);
124
134
  }
125
135
  return reject(new Error("ProductController.initAR() - minimum required attributes not set, use product-id as a minimum"));
@@ -5,6 +5,7 @@ const plattar_api_1 = require("@plattar/plattar-api");
5
5
  const product_ar_1 = require("../../ar/product-ar");
6
6
  const scene_ar_1 = require("../../ar/scene-ar");
7
7
  const scene_product_ar_1 = require("../../ar/scene-product-ar");
8
+ const configurator_state_1 = require("../../util/configurator-state");
8
9
  const util_1 = require("../../util/util");
9
10
  const plattar_controller_1 = require("./plattar-controller");
10
11
  /**
@@ -40,7 +41,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
40
41
  this.removeRenderer();
41
42
  const sceneID = this.getAttribute("scene-id");
42
43
  if (sceneID) {
43
- const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
44
+ const opt = options || this._GetDefaultQROptions();
44
45
  const viewer = document.createElement("plattar-qrcode");
45
46
  // required attributes with defaults for plattar-viewer node
46
47
  const width = this.getAttribute("width") || "500px";
@@ -56,10 +57,12 @@ class ViewerController extends plattar_controller_1.PlattarController {
56
57
  if (opt.qrType) {
57
58
  viewer.setAttribute("qr-type", opt.qrType);
58
59
  }
60
+ viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
59
61
  let dst = plattar_api_1.Server.location().base + "renderer/viewer.html?scene_id=" + sceneID;
60
62
  // optional attributes
61
63
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
62
64
  const variationID = this.getAttribute("variation-id");
65
+ const variationSKU = this.getAttribute("variation-sku");
63
66
  const showAR = this.getAttribute("show-ar");
64
67
  if (productID) {
65
68
  dst += "&productId=" + productID;
@@ -67,6 +70,9 @@ class ViewerController extends plattar_controller_1.PlattarController {
67
70
  if (variationID) {
68
71
  dst += "&variationId=" + variationID;
69
72
  }
73
+ if (variationSKU) {
74
+ dst += "&variationSku=" + variationSKU;
75
+ }
70
76
  if (showAR) {
71
77
  dst += "&show_ar=" + showAR;
72
78
  }
@@ -101,6 +107,7 @@ class ViewerController extends plattar_controller_1.PlattarController {
101
107
  // optional attributes
102
108
  const productID = (this.getAttribute("product-id") || this.getAttribute("scene-product-id"));
103
109
  const variationID = this.getAttribute("variation-id");
110
+ const variationSKU = this.getAttribute("variation-sku");
104
111
  const showAR = this.getAttribute("show-ar");
105
112
  if (productID) {
106
113
  viewer.setAttribute("product-id", productID);
@@ -108,6 +115,9 @@ class ViewerController extends plattar_controller_1.PlattarController {
108
115
  if (variationID) {
109
116
  viewer.setAttribute("variation-id", variationID);
110
117
  }
118
+ if (variationSKU) {
119
+ viewer.setAttribute("variation-sku", variationSKU);
120
+ }
111
121
  if (showAR) {
112
122
  viewer.setAttribute("show-ar", showAR);
113
123
  }
@@ -131,22 +141,39 @@ class ViewerController extends plattar_controller_1.PlattarController {
131
141
  // use product-id if available
132
142
  if (productID) {
133
143
  const variationID = this.getAttribute("variation-id");
134
- const product = new product_ar_1.ProductAR(productID, variationID);
144
+ const variationSKU = this.getAttribute("variation-sku");
145
+ const product = new product_ar_1.ProductAR(productID, variationID, variationSKU);
135
146
  return product.init().then(accept).catch(reject);
136
147
  }
137
148
  const sceneProductID = this.getAttribute("scene-product-id");
138
149
  // use scene-product-id if available
139
150
  if (sceneProductID) {
140
151
  const variationID = this.getAttribute("variation-id");
141
- const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID);
152
+ const variationSKU = this.getAttribute("variation-sku");
153
+ const product = new scene_product_ar_1.SceneProductAR(sceneProductID, variationID, variationSKU);
142
154
  return product.init().then(accept).catch(reject);
143
155
  }
144
156
  const sceneID = this.getAttribute("scene-id");
145
157
  // fallback to using default SceneAR implementation
146
158
  if (sceneID) {
147
- const sceneAR = new scene_ar_1.SceneAR(sceneID);
148
- sceneAR.init().then(accept).catch(reject);
149
- return;
159
+ // special case - check if scene only has a single product, if so
160
+ // we need to use provided variation-id or variation-sku to override
161
+ const variationID = this.getAttribute("variation-id");
162
+ const variationSKU = this.getAttribute("variation-sku");
163
+ // just do scene-ar if variation ID and variation SKU is not set
164
+ if (!variationID && !variationSKU) {
165
+ const sceneAR = new scene_ar_1.SceneAR(sceneID);
166
+ return sceneAR.init().then(accept).catch(reject);
167
+ }
168
+ // otherwise decode scene
169
+ return configurator_state_1.ConfiguratorState.decodeScene(sceneID).then((state) => {
170
+ const firstProduct = state.first();
171
+ if (state.length > 1 || !firstProduct) {
172
+ return reject(new Error("ViewerController.initAR() - single product required to override variation-id or variation-sku"));
173
+ }
174
+ const product = new scene_product_ar_1.SceneProductAR(firstProduct.scene_product_id, variationID, variationSKU);
175
+ return product.init().then(accept).catch(reject);
176
+ }).catch(reject);
150
177
  }
151
178
  return reject(new Error("ViewerController.initAR() - minimum required attributes not set, use scene-id as a minimum"));
152
179
  });
@@ -28,7 +28,7 @@ class VTOController extends plattar_controller_1.PlattarController {
28
28
  this.removeRenderer();
29
29
  const sceneID = this.getAttribute("scene-id");
30
30
  if (sceneID) {
31
- const opt = options || plattar_controller_1.PlattarController.DEFAULT_QR_OPTIONS;
31
+ const opt = options || this._GetDefaultQROptions();
32
32
  const viewer = document.createElement("plattar-qrcode");
33
33
  // required attributes with defaults for plattar-viewer node
34
34
  const width = this.getAttribute("width") || "500px";
@@ -44,6 +44,7 @@ class VTOController extends plattar_controller_1.PlattarController {
44
44
  if (opt.qrType) {
45
45
  viewer.setAttribute("qr-type", opt.qrType);
46
46
  }
47
+ viewer.setAttribute("shorten", (opt.shorten && (opt.shorten === true || opt.shorten === "true")) ? "true" : "false");
47
48
  let dst = plattar_api_1.Server.location().base + "renderer/facear.html?scene_id=" + sceneID;
48
49
  // optional attributes
49
50
  const configState = this.getAttribute("config-state");
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "1.130.2";
1
+ declare const _default: "1.132.1";
2
2
  export default _default;
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = "1.130.2";
3
+ exports.default = "1.132.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plattar/plattar-ar-adapter",
3
- "version": "1.130.2",
3
+ "version": "1.132.1",
4
4
  "description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -41,15 +41,15 @@
41
41
  "@plattar/plattar-api": "^1.120.1",
42
42
  "@plattar/plattar-qrcode": "1.122.1",
43
43
  "@plattar/plattar-services": "^1.120.1",
44
- "@plattar/plattar-web": "^1.129.1"
44
+ "@plattar/plattar-web": "^1.131.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/cli": "^7.17.10",
48
- "@babel/core": "^7.17.10",
49
- "@babel/preset-env": "^7.17.10",
48
+ "@babel/core": "^7.18.5",
49
+ "@babel/preset-env": "^7.18.2",
50
50
  "browserify": "^17.0.0",
51
- "typescript": "^4.6.4",
52
- "uglify-js": "^3.15.5"
51
+ "typescript": "^4.7.3",
52
+ "uglify-js": "^3.16.0"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"